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

synchronous communication (without USART and I2C)

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







synchronous communication (without USART and I2C)
PostPosted: Wed May 12, 2004 12:44 am     Reply with quote

Hi,

i need some advises. I am trying to make a synchronous bidirectional communication between a sensor and my microcontroller using a simple I/O pin. I can not use the USART or I2C (they are already used for another application).
It is my very first microcontroller program so any help would be really appreciated.

Vince
andyfraser



Joined: 04 May 2004
Posts: 47
Location: UK

View user's profile Send private message

PostPosted: Wed May 12, 2004 5:19 am     Reply with quote

Vince,

If your sensor is an I2C device then you can use #use I2C specifying the two port pins you have available. If the device is SPI then it is a bit more tricky and you may have to bit-bang the ports. The basic principle of synchronous serial communications is to generate a clock on one port pin while either setting the state of the serial data out pin and/or reading the state of the serial data in pin. Some example pseudo code follows.

Sending/Receiving a byte
Code:

Set clock port pin to idle level.
Loop:
    Is MSB of byte to send set ?
    Yes:    Set serial data out pin high.
     No:    Set serial data out pin low.
    Set clock port pin to active level.   
    Wait a small period of time.
    Set clock port pin to idle level.
    Wait a small period of time.
    *Read serial data in pin.
    *Set LSB of receive byte to state of serial data in pin.
    *Shift receive byte left one bit.
    Shift byte to be sent left one bit.
Loop 8 times.
Return byte read.

The above pseudo code assumes that the byte is sent MSB first.
*In SPI data transfer is full duplex so while data is being clocked out, the sensor may return data to the microcontroller at the same time. To cater for this condition, after you have taken the clock back to the idle state, you need to read the serial data in pin, place this bit into the LSB of your receive byte then shift the receive byte left one as shown above. If the sensor only returns data, you can simply send a 0 which will generate the necessary clock cycles to allow the sensor to return it's data.

Hope this helps

Andy
vinc
Guest







i ll try it
PostPosted: Wed May 12, 2004 5:48 am     Reply with quote

thx u Ansy 4 the fast answer. i ll try 2 do what u suggest me. hope i ll get good results

Vinc
vinc
Guest







PostPosted: Wed May 12, 2004 5:49 am     Reply with quote

sorry i spell ur name wrongly Confused
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