View previous topic :: View next topic |
Author |
Message |
Srigopal007
Joined: 13 Jun 2005 Posts: 11
|
help with SPI clarafication |
Posted: Mon Jun 13, 2005 5:08 pm |
|
|
I am a newbie to the CCS compiler and barely getting used to the different commands. I have been using PICBasic PRO Compiler from MicroEngineering LABs for most of last year. I finally decided to give the C compiler a try and finally purchased one for myself. I want to shift out bits from the SPI port. The transmission of the bits from the SPI port must be when the clock is transitioning from Low to High. And the Prescalar value must be 16.
I have read the manual along with a few Posts from the search results I obtained from the forum.
Here is what I have so far and I just want to make sure that I am doing this right.
include <16F877A.h>
#use delay (clock = 20000000) /*Using 20Mhz External clock
#fuse HS, NOWDT
void main ()
{
int16 Data0, Data1, Data2;
setup_spi (SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16)
While(1) 'Do this forever
{
spi_write(Data0); 'Sending 16 bits
spi_write(Data1); 'Sending 16 bits
spi_write(Data2); 'sending 16 bits
}
}
Any help with this problem will be greatly appreciated. thanks
Srig |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 13, 2005 6:36 pm |
|
|
I checked it on the logic analyzer, and the data does change on
the rising edge of clock with your SPI setup code. The idle level
for clock is a logic zero. Clock frequency measures at 1.25 MHz. |
|
|
Ttelmah Guest
|
|
Posted: Tue Jun 14, 2005 4:50 am |
|
|
The obvious 'fault', is that the hardware SPI, writes _8bits_. It cannot write a 16bit value as one transaction. To send a 16bit value, you have to output the two bytes one after the other. So:
Code: |
void spi_write16(int16 val) {
spi_write(make8(val,1));
spi_write(make8(val,0));
}
|
Will write the 16bit values you are trying to send.
Best Wishes |
|
|
srig Guest
|
|
Posted: Tue Jun 14, 2005 10:57 am |
|
|
Wow if that is all I have to do to send out data serially through the SPI port than I can get quite used to programming in CCS. thanks for your help.. Will ask more question when I come across them in the future. but many thanks for the help.
Srig |
|
|
|