Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem with SPI and ISD1730

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Sat Apr 26, 2014 10:10 pm    Post subject: Problem with SPI and ISD1730 Reply with quote

Hi

i involving with ISD1730 in 1 week. but i can't run it.

i read its datasheets and wrote some code, but it can't run ISD1730. please help me.

my code :
Code:



$regfile = "m8adef.dat"
$crystal = 8000000

$hwstack = 64
$swstack = 64
$framesize = 64

$baud = 9600


Config Portb.2 = Output
Cs Alias Portb.2

Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 16 , Noss = 1
Spiinit
Waitms 200

Set Cs
Waitms 10


Dim Retry As Byte , N As Byte , Getinput As Byte
Dim D(10) As Byte

Dim Strg As String * 8

Declare Sub Spi_txrx
Declare Sub Power_up
Declare Sub Power_down
Declare Sub Rd_status
Declare Sub Show_msg
Declare Sub Rec
Declare Sub Clr_int
Declare Sub Play
Declare Sub Stp
Declare Sub Eras
Declare Sub Dev_id
Declare Sub Rst


Print "**Start**"

Power_up


Do

  Show_msg

  Input "?" , Getinput

  Power_up

  Select Case Getinput

   Case 1
     Play
     Clr_int

   Case 2
     Power_up

   Case 3
     Power_down

   Case 4
     Stp

   Case 5
     Rec
     Clr_int

   Case 6
     Eras

   Case 7
     Rst

   Case 8
     Dev_id

   Case Else
     Print "Not in Case statement"

  End Select


Loop


'--------------------------------------------------------------------------
'Device Power up

Sub Power_up

  D(1) = &H01 : D(2) = &H00

  Reset Cs
  Waitus 2

  Spiout D(1) , 2
  Spiin D(1) , 2

  Waitus 2
  Set Cs

  Print "SR0 Byte1:" ; Bin(d(1)) ; " = A2,A1,A0,INT,EOM,PU,Full,CMD_Err"
  Print "SR0 Byte2:" ; Bin(d(2))

  If D(1).0 = 0 Then                                        'Check CMD_Err
    Print "Power_up OK"
    Print
    Retry = 0
    Waitms 200
    Clr_int

   Else
     Incr Retry
     Waitms 300
     Print "Power_up NOT OK, Retry... : " ; Retry
     Print
     Power_up

  End If

End Sub

'--------------------------------------------------------------------------
'Device Power down

Sub Power_down

  D(1) = &H07 : D(2) = &H00

  Reset Cs
  Waitus 2

  Spiout D(1) , 2

  Waitus 2
  Set Cs

End Sub

'--------------------------------------------------------------------------
'Read Device-ID

Sub Dev_id

  N = 3
  D(1) = &H09 : D(2) = &H00 : D(3) = &H00
  Spi_txrx

  If D(1).2 = 1 Then
   Print "Reading Dev_id ok"
   Print "SR0 Byte1:" ; Bin(d(1))
   Print "SR0 Byte2:" ; Bin(d(2))
   Print "DEVID    :" ; Bin(d(3))                           'valid ID
   Print

  Else
   Print "Reading Dev_id fail"                              'oder CMD_Error?
   Print "SR0 Byte1:" ; Bin(d(1))
   Print "SR0 Byte2:" ; Bin(d(2))
   Print "DEVID    :" ; Bin(d(3))
   Print "Would Be :" ; "01000000"
   Print

  End If

End Sub


'--------------------------------------------------------------------------
'Play

Sub Play

  N = 2
  D(1) = &H40 : D(2) = &H0
  Spi_txrx

  If D(1).0 = 0 Then                                        'Check CDM-Err

    Print "Playing..."

    Do
      Waitms 100
      N = 3
      D(1) = &H05 : D(2) = &H00 : D(3) = &H00
      Spi_txrx
      Waitms 20
    Loop Until D(1).4 = 1                                   'Check INT

    Clr_int


   Else
    Waitms 200
    Print "occur an err in Play, Retry..."
    Print
    Play

  End If

End Sub

'--------------------------------------------------------------------------
'erase

Sub Eras

  N = 2
  D(1) = &H42 : D(2) = &H00
  Spi_txrx

  If D(1).4 = 1 Then
    Waitms 100
    Print "Stop Complete"
    Clr_int
  End If


End Sub

'--------------------------------------------------------------------------
'Record

Sub Rec

  N = 2
  D(1) = &H41 : D(2) = &H00
  Spi_txrx

  If D(1).0 = 0 Then                                        'Check CDM-Err
    Waitms 100
    Print "Recording..."
    Print
    Clr_int

   Else
    Waitms 200
    Print "occur an err in Rec, Retry..."
    Print
    Rec

  End If

End Sub


'--------------------------------------------------------------------------
'stop

Sub Stp

  N = 2
  D(1) = &H02 : D(2) = &H00
  Spi_txrx

  If D(1).4 = 1 Then                                        'Check INT
    Waitms 100
    Print "Stop Done"
    Print
    Clr_int

   Else
    Waitms 100
    Print "occur an err in Stop, Retry..."
    Print
    Stp

  End If

End Sub

'--------------------------------------------------------------------------
'Device reset

Sub Rst

  N = 2
  D(1) = &H03 : D(2) = &H00
  Spi_txrx

End Sub

'--------------------------------------------------------------------------
'clear INT & EOM

Sub Clr_int

  N = 2
  D(1) = &H04 : D(2) = &H00
  Spi_txrx


  If D(1).4 = 0 Then
    Print "Clr_Int Done"
    Print
    Rd_status

   Else
     Waitms 200
     Clr_int
     Print "Clr_Int Retry..."
     Print

  End If


End Sub

'--------------------------------------------------------------------------
'Read SR1
Sub Rd_status

  N = 3
  D(1) = &H05 : D(2) = &H00 : D(3) = &H00
  Spi_txrx

  If D(3).0 = 1 Then
    Print "Device Ready"
    Print

   Else
     Waitms 200
     Print "Device Not Ready, Retry..."
     Print
     Rd_status

  End If

  Portb.1 = 1
  Waitms 200
  Portb.1 = 0

End Sub

'--------------------------------------------------------------------------
'SPI

Sub Spi_txrx

 Reset Cs
 Waitus 2

 Spiout D(1) , N
 Spiin D(1) , N

 Waitus 2
 Set Cs

End Sub


'--------------------------------------------------------------------------
Sub Show_msg

Print
Print "***************** DEMO ISD1700 over SPI ***********************"
Print
Print "1 Play              2 Power Up"
Print "3 Power Down        4 Stop"
Print "5 Record            6 Erase"
Print "7 Reset             8 Device ID"
Print

End Sub
 


also i used from flowchart in datasheets in page of 60. i attached it.

(BASCOM-AVR version : 2.0.7.7 )

_________________
www.mrkelectronic.blogfa.com

Best Regards
Back to top
View user's profile Visit poster's website Yahoo Messenger
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Sun Apr 27, 2014 12:57 pm    Post subject: Reply with quote

When using the Noss option you need to setup the CS pin after the config SPI , but before the spiinit.
Code:

$baud = 9600




Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 16 , Noss = 1

Config Portb.2 = Output
Cs Alias Portb.2
Set Cs

Spiinit

Waitms 200
 

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Sun Apr 27, 2014 3:19 pm    Post subject: Reply with quote

Thanks Evert

i try it. but my code don't work yet! Sad

_________________
www.mrkelectronic.blogfa.com

Best Regards
Back to top
View user's profile Visit poster's website Yahoo Messenger
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Sun Apr 27, 2014 5:57 pm    Post subject: Reply with quote

what DEVID do you get ?


Some of the IISD1730 read DEVID 1760 (10100000) rather than 1730 (10000000)

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Mon Apr 28, 2014 8:48 am    Post subject: Reply with quote

thanks kimmi

i successfull finaly! the below code working good, this is demo and i wrote it with combination several code from the web and ISD1700 datasheets of course.

all things is ok, but the LED sometimes don't blink! i don't know! also PLAY statement run 2 time for me! i don't have any idea for it!

i complete this code and share it.

new code :

Code:

'-------------------------------------------------------------------------------
'         In The Name Of GOD

'Topic  : ISD1700 Driver Demo
'Author : Morteza Rahimi Kordmahalle (MRK)
'Microcontroller : ATmega8A

'Compiler : BASCOM 2.0.7.6
'Creation Date : Apr 28, 2014 ( 1393.02.08 )
'Copyright : (C) 2014 By www.mrkelectronic.blogfa.com

'-------------------------------------------------------------------------------
$regfile = "m8adef.dat"
$crystal = 8000000
'$crystal = 8000000

$hwstack = 64
$swstack = 64
$framesize = 64

$baud = 9600
'$baud = 4800

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Configurations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 64 , Noss = 0
Spiinit
Waitms 200

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim Retry As Byte , N As Byte , Getinput As Byte
Dim D(10) As Byte
Dim Rdy As Bit

'~~~~~~~~~~~~~~~~~~~~~~~~~~~ Declare Subroutines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Declare Sub Spi_txrx
Declare Sub Power_up
Declare Sub Power_down
Declare Sub Rd_status
Declare Sub Show_msg
Declare Sub Set_rec
Declare Sub Clr_int
Declare Sub Set_play
Declare Sub Stp
Declare Sub Set_eras
Declare Sub Dev_id
Declare Sub Rst

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initializations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Print "**Start**"

Power_up

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Main Program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do

  Show_msg

  Input "your code >: " , Getinput
  Print

  Select Case Getinput

   Case 1
     Set_rec
     Clr_int

   Case 2
     Stp
     Clr_int

   Case 3
     Set_play
     Clr_int

   Case 4
     Set_eras
     Clr_int

   Case 5
     Power_up
     Clr_int

   Case 6
     Power_down

   Case 7
     Rst
     Clr_int

   Case 8
     Dev_id

   Case 9
     Rd_status

   Case Else
     Print "Not Valid Code!"

  End Select


Loop

End

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  Subroutines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'--------------------------------------------------------------------------
'Device Power up

Sub Power_up

  D(1) = &H01 : D(2) = &H00

  Waitus 2

  Spiout D(1) , 2
  Spiin D(1) , 2

  Waitus 2

  Print "SR0 Byte1: A2  A1  A0  INT  EOM  PU  Full  CMD_Err"
  Print "SR0 Byte1: " ; D(3).7 ; "   " ; D(3).6 ; "   " ; D(3).5 ; "    " ; D(3).4 ; "    " ; D(3).3 ; "   " ; D(3).2 ; "    " ; D(3).1 ; "     " ; D(3).0
  Print
  Print "SR0 Byte2: Address Byte > " ; Bin(d(2))
  Print

  If D(1).0 = 0 Then                                        'Check CMD-Err
    Print "Power_up OK"
    Print
    Retry = 0
    Waitms 200
    Clr_int

   Else
     Incr Retry
     Waitms 300
     Print "Power_up NOT OK, Retry... : " ; Retry
     Print
     Power_up

  End If

End Sub

'--------------------------------------------------------------------------
'Device Power down

Sub Power_down

  D(1) = &H07 : D(2) = &H00

  Waitus 2

  Spiout D(1) , 2

  Waitus 2

  Print "Power Down..."
  Print

End Sub

'--------------------------------------------------------------------------
'Read Device-ID                   'Maximum Address Value for ISD1730 is &H0FF

Sub Dev_id

  Rd_status

  N = 3
  D(1) = &H09 : D(2) = &H00 : D(3) = &H00
  Spi_txrx

  If D(3) <> 0 Then
    Print "DEVID : " ; Bin(d(3))
    Print

   Else
    Print "Device Not Recognize!!?"
    Print

  End If

End Sub

'--------------------------------------------------------------------------
'Read SR0 & SR1
Sub Rd_status

  N = 3
  D(1) = &H05 : D(2) = &H00 : D(3) = &H00
  Spi_txrx

  Waitms 200

  If D(3).0 = 1 Then
    Rdy = 1
    Print "Device Ready"
    Print

   Else
     Waitms 500
     Rdy = 0
     Print "Device Not Ready, Retry..."
     Print
     Rd_status

  End If

  Print "SR1: SE3 SE2 SE1 SE0 Rec Play Erase RDY"
  Print "SR1:  " ; D(3).7 ; "   " ; D(3).6 ; "   " ; D(3).5 ; "   " ; D(3).4 ; "   " ; D(3).3 ; "   " ; D(3).2 ; "     " ; D(3).1 ; "    " ; D(3).0
  Print

End Sub

'--------------------------------------------------------------------------
'Play

Sub Set_play

  If Rdy = 0 Then Rd_status

  N = 7
  D(1) = &H90 : D(2) = &H00 : D(3) = &H10 : D(4) = &H00 : D(5) = &HFE : D(6) = &H00 : D(7) = &H00
  Spi_txrx

  If D(1).0 = 0 Then                                        'Check CMD-Err
    Waitms 200
    Print "Playing..."
    Rdy = 0
    Clr_int

   Else
    Waitms 200
    Print "occur an err in Play, Retry..."
    Print
    Set_play

  End If


End Sub

'--------------------------------------------------------------------------
'erase

Sub Set_eras

  If Rdy = 0 Then Rd_status

  N = 7
  D(1) = &H92 : D(2) = &H00 : D(3) = &H10 : D(4) = &H00 : D(5) = &HFE : D(6) = &H00 : D(7) = &H00
  Spi_txrx

  If D(1).0 = 0 Then                                        'Check CMD-Err
    Waitms 200
    Print "Erase Complete"
    Rdy = 0
    Clr_int

   Else
     Waitms 200
     Print "occur an err in Erase, Retry..."
     Print
     Set_eras

  End If

End Sub

'--------------------------------------------------------------------------
'Record

Sub Set_rec

  If Rdy = 0 Then Rd_status

  N = 7
  D(1) = &H91 : D(2) = &H00 : D(3) = &H10 : D(4) = &H00 : D(5) = &HFE : D(6) = &H00 : D(7) = &H00
  Spi_txrx

  If D(1).0 = 0 Then                                        'Check CMD-Err
    Waitms 200
    Print "Recording..."
    Print
    Rdy = 0

   Else
    Waitms 200
    Print "occur an err in Rec, Retry..."
    Print
    Set_rec

  End If


End Sub


'--------------------------------------------------------------------------
'Stop

Sub Stp

  N = 2
  D(1) = &H02 : D(2) = &H00
  Spi_txrx

  If D(1).0 = 0 Then                                        'Check CMD-Err
    Waitms 200
    Print "Stop Done"
    Print

   Else
    Waitms 200
    Print "occur an err in Stop, Retry..."
    Print
    Stp

  End If

End Sub

'--------------------------------------------------------------------------
'Device reset

Sub Rst

  If Rdy = 0 Then Rd_status

  N = 2
  D(1) = &H03 : D(2) = &H00
  Spi_txrx

  If D(1).0 = 0 Then                                        'Check CDM-Err
    Waitms 200
    Print "Reset Done"
    Print
    Rdy = 0

   Else
    Waitms 200
    Print "occur an err in Reset, Retry..."
    Print
    Rst

  End If

End Sub

'--------------------------------------------------------------------------
'clear INT & EOM

Sub Clr_int

  N = 2
  D(1) = &H04 : D(2) = &H00
  Spi_txrx

  If D(1).4 = 0 Then
    Print "Clr_Int Done"
    Print

   Else
     Waitms 200
     Clr_int
     Print "Clr_Int Retry..."
     Print

  End If

End Sub

'--------------------------------------------------------------------------
'SPI

Sub Spi_txrx

 Waitus 2

 Spiout D(1) , N
 Spiin D(1) , N

 Waitus 2

End Sub


'--------------------------------------------------------------------------
Sub Show_msg

Print
Print "***************** DEMO ISD1700 over SPI ***********************"
Print
Print "1 Record           2 Stop"
Print "3 Play             4 Erase"
Print "5 Power Up         6 Power Down"
Print "7 Reset            8 Device ID"
Print "9 RD_Status : Read SR0 and SR1   "
Print

End Sub
 
[/code][/quote]
_________________
www.mrkelectronic.blogfa.com

Best Regards
Back to top
View user's profile Visit poster's website Yahoo Messenger
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 28, 2014 10:21 am    Post subject: Reply with quote

nice Very Happy
one thing : when using NOSS=1 , you MUST set the SS pin to output. Even if you do not use it. Otherwise when it picks up a 1 the hardware will be set to slave mode. That is something of the avr hardware.
i would recommend to set the port pin before the config spi.

_________________
Mark
Back to top
View user's profile Visit poster's website
Ajaxelectronic

Bascom Member



Joined: 22 Nov 2009
Posts: 171
Location: Iran

iran.gif
PostPosted: Thu May 01, 2014 11:40 am    Post subject: Reply with quote

thanks albert

i share my work in the below topic :

http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&p=64384#64384

_________________
www.mrkelectronic.blogfa.com

Best Regards
Back to top
View user's profile Visit poster's website Yahoo Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum