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

help with SPI clarafication

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



Joined: 13 Jun 2005
Posts: 11

View user's profile Send private message

help with SPI clarafication
PostPosted: Mon Jun 13, 2005 5:08 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 13, 2005 6:36 pm     Reply with quote

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







PostPosted: Tue Jun 14, 2005 4:50 am     Reply with quote

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







PostPosted: Tue Jun 14, 2005 10:57 am     Reply with quote

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
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