Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

twi slave how to send more than one byte?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 112

poland.gif
PostPosted: Thu Mar 23, 2017 7:40 am    Post subject: twi slave how to send more than one byte? Reply with quote

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:

 select case BTR
   case 1 : twi=0  'no move
   case 2 twi=100 'low of encoder val
   case 3 twi=150 'high of encoder val
 end select
 
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?

Martin
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Mar 23, 2017 9:11 am    Post subject: Reply with quote

This is from the samples :
Code:

'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
  Select Case Twi_btr
    Case 1:                                                 ' 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)
    Case 2                                                  ' send second byte
              Twi = High(w)
  End Select
Return

 


note that the PI does not support clock stretching.

_________________
Mark
Back to top
View user's profile Visit poster's website
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 112

poland.gif
PostPosted: Thu Mar 23, 2017 10:15 am    Post subject: Reply with quote

Thank ypu for an answer. I'll check it at home.

Martin
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum