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

Software SPI on 18F4525

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



Joined: 15 Nov 2004
Posts: 18

View user's profile Send private message

Software SPI on 18F4525
PostPosted: Mon Aug 23, 2010 5:21 pm     Reply with quote

Hello,

I need a software SPI for my cc240 radio. It runs fine with hw SPI, but the sw version on an 18F4525 does not work.

I use this code:
Code:

#USE SPI (MASTER,MSB_FIRST,DI=pin_A5,DO=pin_E1,CLK=pin_E0,Mode=3,CLOCK_HIGH=10,CLOCK_LOW=10)

unsigned char CC2420_Command( char command )
{
output_low(CSeb);
delay_ms(ms);
spi_xfer(command);
delay_ms(ms);
//spi_write(command);
output_high(CSeb);

return ( 0 ); // if WCOL bit is not set return non-negative#
}

I'm still experimenting and the signals look OK on my o'scope.

I'm open to suggestions.

Klaus
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 23, 2010 6:30 pm     Reply with quote

1. How do you know it's not working ? What test are you doing to check
if it works ? Are you just writing and reading back from a register ?
If so, post a compilable test program that does the test.

2. Post your compiler version.

3. Post the (working) hardware SPI version of a small test program.
Then it's easy to compare it to your software SPI program.

4. What happens if you use the hardware SPI pins for your software SPI
test ? That's the way I would have done it. Then, the number of things
that you have changed are kept limited to the SPI method. If you
change both the SPI method and the pins that are used, you make it
more difficult to decide where the problem is located.
klausdejong



Joined: 15 Nov 2004
Posts: 18

View user's profile Send private message

PostPosted: Mon Aug 23, 2010 7:07 pm     Reply with quote

Dear PCM programmer,

Again there are interesting and promising suggestions in your reply.

Especially your suggestion to find a small test routine is useful. And your suggestion to look for parallels for hw and sw SPI makes sense.

It is not so easy to compare hw and sw SPI with my hardware but could be done.

OK, a lot of work to do,

Klaus
klausdejong



Joined: 15 Nov 2004
Posts: 18

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 5:41 pm     Reply with quote

I work with cc2420 IEEE transceivers. They all have hw SPI but 1 has software SPI.

My conclusion this far is that the transmitter, hw SPI, and the receiver, sw SPI, do not cooperate due to the speed difference between hw and sf SPI.

Is this a feasable conclusion? All other causes are tested and excluded.

Regards,

Klaus
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 9:11 pm     Reply with quote

Test your theory. Here are 3 ways:

1. Switch the transmitter PIC to use software SPI and the receiver PIC
to hardware SPI.

2. Or, slow down the SCLK speed in the hardware SPI transmitter PIC.
Use a 4 MHz oscillator for the PIC, and then use this SPI divisor:
Code:
SPI_CLK_DIV_64 

That will give you a 62.5 KHz SCLK for the transmitter.

3. Or, put time delays between the spi_write() statements in the
transmitter PIC. Use delay_ms(1) or some larger value.

In other words, slow down the transmitter PIC, compared to the receiver
PIC. This will test your theory.
klausdejong



Joined: 15 Nov 2004
Posts: 18

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 1:15 pm     Reply with quote

I tested my theory and it is not valid.

I changed hw and sw SPI, slowed down the clock and put in small delays but it does not help.

So, I stop at this point. Maybe I will pick it up again in a while or I design a new board with hw SPI for this application. It will be the second option, I guess.

Regards,

Klaus
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