CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Trouble with spi from PIC18F452 -> VS1002d (dsp)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
uni_student



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

View user's profile Send private message Send e-mail MSN Messenger

Trouble with spi from PIC18F452 -> VS1002d (dsp)
PostPosted: Wed Aug 01, 2007 8:13 pm     Reply with quote

First attempt at anything using SPI. Im following a test application that is described with the application notes on the VS1002d dsp. Using PIC as master, using 12.288Mhz clock for the dsp.

I am unsure what baud rate i should be setting?
And the following code is not working.
DREQ is working so only the first "LED" is lighting up.

Any help appreciated.


[#include <18f452.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#use RS232 (baud=4800, xmit=PIN_C5, rcv=PIN_C4)

#define DREQ PIN_E2
#define xCS PIN_C1
#define LED PIN_A1
#define LED2 PIN_A2
#define LED3 PIN_A3
#define RESET PIN_C0

void main(){
int value, value2;
setup_spi(spi_master | spi_l_to_h | spi_clk_div_16);
set_tris_e(0xFF); //??
set_tris_c(0x10); //??

value = 0;

value2 = 0;
output_high(RESET);

output_low(xCS);
while(TRUE){
if(input(DREQ)){
output_high(LED);
spi_write(0x2);
spi_write(0xB);
spi_write(0xA2);
spi_write(0xF5);
delay_us(5);
output_high(xCS);
delay_us(5);
output_low(xCS);
spi_write(0x3);
spi_write(0xB);
value = spi_read(0x22);
value2 = spi_read(0x33);
delay_us(5);
output_high(xCS);
while (TRUE) {
if(value == 0xA2){
output_high(LED2);
}
if(value2 == 0xF5){
output_high(LED3);
}
}
}

}
}
]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 01, 2007 8:31 pm     Reply with quote

Quote:
#use RS232 (baud=4800, xmit=PIN_C5, rcv=PIN_C4)

Pins C4 and C5 are used by the hardware SPI module. Don't use them
for the UART. Use the hardware UART pins. Also add the ERRORS
directive. Example:
Code:
#use RS232 (baud=4800, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

Also change the wiring on your board so it uses the hardware UART pins.


Quote:
set_tris_e(0xFF); //??
set_tris_c(0x10); //??

Don't bother setting the TRIS. Let the compiler do it for you.
In "standard i/o" mode (the default mode), if you use the CCS pin i/o
functions, such as output_low(), etc., the compiler will set the correct
TRIS automatically. Delete those two lines.


Quote:
setup_spi(spi_master | spi_l_to_h | spi_clk_div_16);

Check the DSP data sheet and see what SPI mode it uses.
See my post in this thread, which tells how to easily setup the correct
SPI mode:
http://www.ccsinfo.com/forum/viewtopic.php?t=31271


Quote:
value = spi_read(0x22);
value2 = spi_read(0x33);

I'm not sure what you're doing here. I haven't read the DSP data sheet.
Be aware that as the spi_read() is performed and data is shifted in from
the DSP, the 1st line will shift out 0x22 to the DSP and the 2nd line will
shift out 0x33. Normally, a parameter of 0x00 is used with the
spi_read() statement. That's because only a one-way transfer of data
is performed, from the SPI slave to the master (the PIC), so you just
set the shift-out data to 0x00. Carefully read the DSP spec and make
sure if you're supposed to do this (shift out 0x22 and 0x33), or to do it
during an SPI read.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group