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 help !!!
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 9:09 am     Reply with quote

nahumof wrote:


Code from Ttelmah
Code:

void send_spi_byte(int8 ClockPin, int8 DataOutPin,int8 val_to_send) {
   int8 count;
   for (count=0;count<8;count++) {
      output_bit(DataOutPin, shift_left(&val_to_send,1,0));
      output_high(ClockPin);
      output_low(ClockPin);
   }
}

int8 get_spi_byte(int8 ClockPin, int8 DataInPin) {
   int8 count;
   int8 val;
   for (count=0;count<8;count++) {
      output_high(ClockPin);
      shift_left(&val,1,input(DataInPin));
      output_low(ClockPin);
   }
   return(val);
}


I could use #use_spi as pic slave?
tks Smile


I posted that code and Ttelmah pointed out when I did:

Quote:
Beware:
Pin definitions need to be an int16, for a PIC18. int8 definition, will only work for a PIC12/16.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Apr 11, 2011 10:45 am     Reply with quote

Geps wrote:
I posted that code and Ttelmah pointed out when I did:

Quote:
Beware:
Pin definitions need to be an int16, for a PIC18. int8 definition, will only work for a PIC12/16.

Best Wishes
Thanks for explaining the error in the posted code, but you are missing the point that Nahumof is looking for a software SPI slave routine. Your code is for a SPI master.

Lets try to stay on topic.
nahumof



Joined: 09 Apr 2011
Posts: 15

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 4:02 pm     Reply with quote

tks ckielstra

i will try to use uart or rebuild the hardware... i was using spi because i got 6 devices 1 pic master 2 slaves and 3 devices slaves spi.

master
1 master 18f4550 USB

slave
1 slave 16f876a is just for control a glcd display
1 slave 16f876a is for control a pid on a electro estimulator

devices
1 device adc for control touch
1 device adc amplifier input
1 device micro sd for recording

i thought it will be more easy to handle a single bus for all devices

Rolling Eyes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 14, 2011 7:06 am     Reply with quote

nahumof wrote:
1 device micro sd for recording
A design hint here, to protect you from making the design error we made:
Writing to the SD card is always done in blocks of 512 bytes, this will take some time. So, if you have time critical processes running on the other SPI devices you might be better of to add an extra SPI bus for the fast devices. In the master it is easy to add a software SPI master routine.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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