PDA

View Full Version : isd4002 problems help required please



Agent36
- 27th September 2006, 21:46
Hi,
I have down loaded and modified the following code from MELABS samples so I can understand the coding.
I have changed the code so that I have three push buttons record, finish and play. The binary switch on porta selects the address to start playing the message . The problem is I can only play from address zero, if some one would be kind enough to check the code and point me in the right direction it would be a great help. I have spent four weeks on this with out progression.
Here is the code in full.




' Program to record and play multiple voice messages.
' Uses hardware SPI for 2-way communication to the voice device.
' Record messages in sequence by pressing the REC button.
' Then pressing the FINISH button to stop recording. The messages
' may be played back by selecting the address on the deciaml to binary
' switch and pressing the PLAY button.


@ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE PIC16F819, WDT_ON
' Watchdog Timer
@ DEVICE PIC16F819, PWRT_ON
' Power-On Timer
@ DEVICE PIC16F819, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE PIC16F819, BOD_OFF
' Brown-Out Detect
@ DEVICE PIC16F819, CPD_OFF
' Data Memory Code Protect
@ DEVICE PIC16F819, PROTECT_OFF





DEFINE OSC 8 ' Define for 8MHz crystal internal

OSCCON = $70 'set the clock to 8 Mhz, 60 for 4MHz


select_voice VAR PORTB.3 ' Chip select for voice recorder
serial_mcu_out VAR PORTB.2 ' SPI data output
serial_clk VAR PORTB.4 ' SPI clock pin
voice_int VAR PORTB.5 ' Interrupt signal from voice device


ADCON1 = 7 ' Set PORTA and PORTB to digital


' Define program variables


control VAR BYTE
address VAR WORD
isd_data_in VAR WORD
isd_data_out VAR WORD
message_loc VAR WORD[16]
i VAR BYTE

i = 0
message_loc[0]=0


' set up SPI port
BF VAR SSPSTAT.0 ' Alias Buffer Full flag
SSPSTAT = %01000000 ' Set SMP=0, CKE=1
SSPCON = %00100010 ' Set CKP=0, SPI master, clock = Fosc/64, Enable the port
TRISB = %11100011 ' Set data-direction to allow SPI on PortB

High select_voice

'portb.0 is Play
'portb.1 is MCU IN (SDI)
'portb.2 is MCU OUT (SDO)
'portb.3 is Select voice
'portb.4 is Serial clock (SCK)
'portb.5 is Voice int (SS)
'portb.6 is Record start
'portb.7 is Record Finish

TRISA = %00001111 'Bits 0-3 address select





Pause 1000 ' allows power to settle


loop:
IF PORTB.6 = 0 Then
address = message_loc[i] 'Sets address to begin recording
GoSub record
EndIF

IF PORTB.7 = 0 Then
GoSub finish
i = (i+1) & $0F
message_loc[i] = (isd_data_in >> 2) + 2 ' remove status bit
EndIF

IF PORTB.0 = 0 Then
Pause 500 'allow key to release
i = PORTA ' number selected plays corresponding message
i = i+$0F
address = message_loc[i] 'sets playback address
GoSub ply
EndIF

wait_for_int:

IF voice_int = 1 Then
GoTo wait_for_int 'loop here till finished
GoSub finish 'power down chip
EndIF




GoTo loop ' Do it forever









' ISD4003 Control Values:
power_up CON %00100000 ' Power up the device
set_play CON %11100000 ' Set the playback address
play CON %11110000 ' Start playback
set_rec CON %10100000 ' Set the record address
rec CON %10110000 ' Start recording
power_dwn CON %00010000 ' Stop playback or record and power down the device


record: 'Record a message
control = power_up ' Set control byte to power up
GoSub spi_send ' Send to device

Pause 100 ' Pause to let the device come up

control = set_rec ' Set control byte to set record address
GoSub spi_send ' Send to device
Return ' Return to main loop


ply:
control = power_up ' Set control byte to power up
GoSub spi_send ' Send to device

Pause 50 ' Pause to let the device come up

control = set_play ' Set control byte to set play address
GoSub spi_send ' Send to device
Return

finish:
control = power_dwn ' Set control byte to power down
GoSub spi_send ' Send to device
Return ' Return to main loop


spi_send: ' Use hardware SPI port to send and receive simultaneously


Low select_voice ' Select voice chip

address.highbyte = (address.highbyte & %00000111) | control ' Combine address and control data
isd_data_out = address REV 16 ' Reverse the bits for LSB first

SSPBUF = isd_data_out.highbyte ' Write the first byte to SSPBUF to initiate trasfer

GoSub spi_wait ' Wait for transfer to finish

isd_data_in.highbyte = SSPBUF ' Read the incoming data from SSPBUF

SSPBUF = isd_data_out.lowbyte ' Write the second byte to SSPBUF to initiate transfer

GoSub spi_wait ' Wait for transfer to finish

isd_data_in.lowbyte = SSPBUF ' Read the incoming data from SSPBUF

isd_data_in = isd_data_in REV 16 ' Reverse the bits of incoming data (received LSB first)

High select_voice ' Deselect voice chip

Return


spi_wait: ' Wait for transfer to finish
IF BF = 0 Then spi_wait ' If the flag is still zero, keep waiting
BF = 0 ' Reset the flag
Return


End


Thanks for your help and time

Kind regards

Nick

khoog
- 28th September 2006, 01:43
Hi Nick,

I used the SETPLAY command (%11100000) instead of PLAY (%11110000). It went something like this:

CmdPlay VAR WORD
CmdPwrUp CON %0010000

SHIFTOUT MOSI, SCLK, 0, [CmdPwrUp\8]
HIGH SS
PAUSE 20
LOW SS

CmdPlay = %111000010001011 'SETPLAY + address
SHIFTOUT MOSI, SCLK, 0, [CmdPlay\16]
HIGH SS

Klaus

Agent36
- 28th September 2006, 20:06
Hi Klaus,

Thanks for the code example, I have checked the code and I am using set_play (11100000). The problem I have is reading in the play address using 4 bits on porta and then looking it up in the array. I have included the full code in notepad if you want to look at it. I dont think my 1st post was very clear.

I am going to keep your code sample and play with it once I get this working

thanks again
Nick

charudatt
- 19th October 2006, 17:40
Hi Nick,

Can you share the code once done. I have a similar chip APR6016 to play with.

Thanks for the start code.

regards

BobK
- 20th October 2006, 01:44
Hi Nick,

I haven't used a PIC in this manner but I think the line:
"TRISA = %00001111 'Bits 0-3 address select"
is wrong. TRISA sets the data direction for PortA.

Now if you had "TRISA = %00000000" then all of the lines of PortA are set as outputs. The next line should then be "PortA = %00001111".

This would then turn PortA 0 - 3 on and 4 - 7 off.

BobK

Sorry, I didn't look at the date of the original post!

Agent36
- 20th October 2006, 19:39
Hi BobK,

PortA bits 0-3 are for a binary switch; they set the play address for the isd4002.

charudatt,
I have worked out all the problems myself, now it stores the address to eeprom and can be selected via the binary switch using a lookup table. Is this what you are after? Contact me via email in my personal info and I will send you the completed code.

Regards
Nick

Agent36
- 20th October 2006, 19:56
Hi BobK,

PortA bits 0-3 are for a binary switch; they set the play address for the isd4002.

charudatt,
I have worked out all the problems myself, now it stores the address to eeprom and can be selected via the binary switch using a lookup table. Is this what you are after? Contact me via email in my personal info and I will send you the completed code.

Regards
Nick

charudatt
- 24th October 2006, 18:55
Hi Nick,

Sent You A Pm Some Days Back. Don't Know If You Got It.

Regards
Charudatt

charudatt
- 24th October 2006, 19:06
JUST IN CASE IF SOME ONE WAS INTERESTED, I HAVE A SIMILAR PROJECT USING APR6016 IC.

THIS CONNECTS TO A DEVELOPMENT BOARD FOR CONTROL.

APR6016 IS MANUFACTURED BY APLUS AND THE DATASHEET CAN BE FOUND AT http://www.aplusinc.com.tw/data/recording/data-sheet/apr6016.zip

REGARDS

sathyakiruba
- 29th March 2012, 06:57
dear sir,

i need apr 6016 code for pic 16f877a