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 support@ccsinfo.com

SPI problem with PIC18F4520

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



Joined: 28 Mar 2006
Posts: 5

View user's profile Send private message

SPI problem with PIC18F4520
PostPosted: Sat Apr 01, 2006 1:13 pm     Reply with quote

I am trying to use SPI interface to connect to the STA013 mp3 decoder IC. It looks like it sends the first byte, but then it stops sending the data.
Any ideas???


int8 const mp3[10032]= {0xFF,0xE3,0x10,0xC0,0x00,0x09,0x48,0x02,
0xE3,0xAF,0x40,0x00,0x02,0x96,0x39,0x3E,
0xA0,0x1C,0xDB,0x78,0x93,0x28,0x34,0x31,
0x86,0x04,0x9E,0x73,0x04,0x25,0x38,0x3F,
0xFE,0x18,0xE5,0x1D,0x54,0x31,0xE7,0x22,
0x03,0x9E,0x5F,0xA8,0x1F,0xE5,0xCF,0xD7,
0x0F,0xF5,0x80,0x04,0xFF,0xE3,0x10,0xC0,
0x01,0x09,0xE0,0xE3,0x1F,0x1F,0x81,0x39,
0x02,0x00,0x3D,0x04,0xD0,0x4E,0x04,0x00,
0x00,0x00,0x0A,0x0D,0x0B,0x85,0xC0,0x03,
0xFF,0xE7,0xF4,0x5F,0xD5,0x26,...........};

long int j=0;

void mp3_out()
{
while(j<10032)
{
if (input(PIN_B6))
{

output_a(0x01);
delay_ms(100);
output_b(0x00);
delay_ms(100);
spi_write (mp3[j]);
++j;
}

else if (!input(PIN_B6))
{
output_a(0x02);
delay_ms(100);
output_a(0x00);
delay_ms(100);
}
}
}

void main()
{
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
output_b(0x80);
call_i2c_init();
call_sta013_bin();
mp3_out();

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 01, 2006 1:42 pm     Reply with quote

You are reading Pin B6 then you turn around and whack the whole of
Port B by writing all zeros to it. What device is connected to pin B6 ?
What happens to its output pin when you drive it to a Logic zero from
the PIC ? I don't know. It might not be good.

The 2nd thing is, you've got a 200 ms delay on all spi write operations.
So take 10K and divide it by 5 and you get 2000 seconds to send all
your data. That's over 30 minutes. This will give the appearance
that your program has "locked up".

Finally, you didn't say if you're using a debugger, but if you are,
the debuggers use pins B6 and B7. You can't use them in your
own program while using the debugger.
sven_1669



Joined: 28 Mar 2006
Posts: 5

View user's profile Send private message

PostPosted: Sat Apr 01, 2006 1:51 pm     Reply with quote

pin b6 is the data_req pin from the sta013. When it is high, the decoder wants more data. I will try not setting it all to zero's, and see what that does. Also, I am not using a debugger, so that would not be causing the problem.
sven_1669



Joined: 28 Mar 2006
Posts: 5

View user's profile Send private message

PostPosted: Sat Apr 01, 2006 2:09 pm     Reply with quote

I changed the code from
Code:
 if (input(PIN_B6))
{

output_a(0x01);
delay_ms(100);
output_b(0x00);
delay_ms(100);
spi_write (mp3[j]);
++j;
}

else if (!input(PIN_B6))
{
output_a(0x02);
delay_ms(100);
output_a(0x00);
delay_ms(100);


to
Code:

if (input(PIN_B6))
{
spi_write (mp3[j]);
++j;
}

else
{
output_high(PIN_B0);
delay_ms(100);
output_low(PIN_B0);
delay_ms(100);


I removed the delays and the outputs from the spi section, and just set the pin that i have the LED on high. Same effect. I am not getting anything outputted from the STA013, and the DATA_REQ never goes low to indicate that it has been filled with data. Is there anything wrong with the way i am sending the data using SPI? Is there any other SPI initilizations i have to do besides setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4); ????
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 01, 2006 4:14 pm     Reply with quote

It appears that you're trying to create a driver for the STA013 chip.
My advice is to find an existing driver on the net and convert it to CCS.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Apr 01, 2006 5:58 pm     Reply with quote

The STA013 chip is very versatile which makes it difficult to program, the code for initialising the chip is missing so we can't tell you are configuring the SPI interface correctly. At first glance it looks OK, but how are you handling the BIT_EN line? Is DATA_REQ configured to be active high or low and is SKCR sampled on the rising or falling edge? Etc...

I agree with PCM Programmer, many projects using this chip exist on the internet so you would make life a lot easier on yourself by porting one of those projects.
sven_1669



Joined: 28 Mar 2006
Posts: 5

View user's profile Send private message

PostPosted: Sat Apr 01, 2006 7:05 pm     Reply with quote

alright....thanks for the help....back to the head scratching....
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