Posted: Thu Mar 23, 2017 7:40 am Post subject: twi slave how to send more than one byte?
Hello,
I made a short program to read encodoer with 500 ppr on ATMega8. ATMega8 is the slave and I would like to send some values to the master which is RaspberryPi. When it goes about to send one byte, everything is ok, but how to send an integer or Word value?
What I did: in config of twi slave I declared BTR=3, in the procedure (values in BTE only as an example)
Code:
Twi_master_needs_byte:
selectcase BTR
case1:twi=0'no move case2twi=100'low of encoder val case3twi=150'high of encoder val endselect
Return
on raspberryPi side I have an function wiringPiI2CRead which return LongInt value. But I'm receiving from ATMega8 slave only 255 value. If the code above is correct than i'll look over my pascal code on the Raspberry
but every time this function gives 255 val. Even if all 3 twi will be equal to 1. What do you think, where i do a mistake?
'this label is called when the master receives data and needs a byte 'the variable twi_btr is a byte variable that holds the index of the needed byte 'so when sending multiple bytes from an array, twi_btr can be used for the index
Twi_master_needs_byte: 'Print "Master needs byte : " ; Twi_btr SelectCase Twi_btr
Case1:' first byte
W =Getadc(0)'in this example the conversion is done here ' but a better option would have been to just pass the value of W and do the conversion in the main loop 'Print "ADC-SLAVE:" ; W Twi=Low(w) Case2' send second byte Twi=High(w) EndSelect Return
note that the PI does not support clock stretching. _________________ Mark
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 You cannot attach files in this forum You cannot download files in this forum