View previous topic :: View next topic |
Author |
Message |
klausdejong
Joined: 15 Nov 2004 Posts: 18
|
Software SPI on 18F4525 |
Posted: Mon Aug 23, 2010 5:21 pm |
|
|
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
|
|
Posted: Mon Aug 23, 2010 6:30 pm |
|
|
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
|
|
Posted: Mon Aug 23, 2010 7:07 pm |
|
|
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
|
|
Posted: Tue Aug 24, 2010 5:41 pm |
|
|
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
|
|
Posted: Tue Aug 24, 2010 9:11 pm |
|
|
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:
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
|
|
Posted: Wed Aug 25, 2010 1:15 pm |
|
|
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 |
|
|
|