PDA

View Full Version : HSERIN and I2C ?



cpayne
- 12th October 2005, 04:51
I am trying to write a program in PBP that will receive 15 bytes of data that is sent every 2 seconds. I am setting the PIC16F877 up as and I2C salve so another PIC can get the data and send some data. I have written the basic loop. My quesitons are, do you think the I2C and serial buffer might clash with timing since the serial buffer only has a 2 byte buffer. I am only sending back 8 bytes of the 15 byte array and receiving 1 word via I2C. I would like to receive the word every 250 ms and only need to send the 8 bytes to the I2C master every 2 seconds, but I wasn't planning on syncronizing anything, maybe I should with a IO line? Also is there a more eligant way of receiving an array. Do I have the HSERIN statement typed right? I figured I would only wait 1 ms for the data, if its not there check for I2C and loop. Any thoughts or suggestions would be appreciated. Thanks! Charlie

Below is a snip, I can send the whole thing if its worthwhile.
HSEROUT ["C"] 'fire up the Sensor

mainloop:

IF SSPIF Then ' Check for I2C interrupt flag
GoSub i2cslave
EndIF

HSERIN , 1, Rx_time,[HEX2 L(1),HEX2 L(2),HEX2 L(3),HEX2 L(4),HEX2 L(5),HEX2 L(6),HEX2 L(7),HEX2 L(8),HEX2 L(9),HEX2 L(10),HEX2 L(11),HEX2 L(12),HEX2 L(13),HEX2 L(14),HEX2 L(15)]
resume_main:

gosub SetPWPS 450

GoTo mainloop ' Do it all forever

Rx_Time:

goto resume_main