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

Serial question >.<

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



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Serial question >.<
PostPosted: Tue Nov 30, 2010 10:05 am     Reply with quote

Hey Guys...

I want to use a pic18f46k20 in a project. I need a spi for a sd card and i2c both master and slave. This pic has 2 serial modules.

MY question : I am using the hardware i2c as is but I have a 8bit data bus going to portd where the spi is located. Can I implement the i2c slave and spi in software.

Background:
Pic need to acquire a i2c instruction fro a external board (need a i2c slave). Pic then sends onboard components i2c commands (using hardware i2c pic). Data from onboard hardware is send to portd and is saved on a spi sd card (need spi). External board has its own pullups.

Regards
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Tue Nov 30, 2010 10:12 am     Reply with quote

Yup code below (based originally on code by 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);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Nov 30, 2010 10:34 am     Reply with quote

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

Best Wishes
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Tue Nov 30, 2010 10:52 am     Reply with quote

Cool thx !!
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
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