![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
Newbie Questions on SPI? |
Posted: Thu Jul 27, 2006 2:26 am |
|
|
Hi
I am a newbie to SPI, and am trying to translate some code from an ATMEL chip to a PIC.
The requirement are:
//SPI type: Master
//SPI Clock RatE: 921.6kHz
//SPI Clock Phase: Cycle Half
//SPI Clock Polarity: Low
//SPI Data Order: MSB First
I have the following line:
Code: |
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
|
will this be compatible to the above? or what should I change in order to get it more compatible. (I am planning to use a 16Mhz Xtal).
A second question:
I am using the PIC18F4550, and am not sure what to do about
the CS?
In the ATMEL code CS is set H and L.
Please could you tell me what I should do in the PIC?
Thank you in advance
a. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Jul 27, 2006 8:09 am |
|
|
First comment, you will not get 921.6 KHz, with a 16Mhz crystal. In general, if this is a 'maximum' rate, any speed below this should work (the whole point about SPI, is that it is synchronous, so the master controls the bus timing). The master oscillator/16, will give 1MHz (above the specification you give - check if this may be OK), or you can use timer2, with a 1:1 prescaler, and a division by 3 (then divided by two in the SPI hardware), to give 666KHz. If you must get 921.6KHz exactly, you will need to switch to using a 14.7456MHz crystal, or 22.1184MHz.
Your current selection will give a 1Mhz clock.
CS is simple. Just select a line on the chip, pull it low/high as required before the SPI transaction, then raise/lower it after the work is complete. This is not 'hardwired', because it is common to have multiple SPI peripherals, and you can then simply operate the required CS line for a specific device, handle the transaction, and deselect the device.
MSB first is 'standard' for SPI.
Get a diagram showing what the required clocks are on your target device. The 'names' as given ('cycle half' for example), are terms selected by the particular manufacturer of the device, and without the explanatory diagram (there will be one in the data sheet), do not 'say' what they really mean. I would _guess_without such a diagram, that your current values are close to right (data read at the middle of the bit, falling clock edge at this point, and with the clock idling low).
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|