I2C Slave Device | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSS sp_TopicIcon
I2C Slave Device
August 29, 2019
7:58 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

We recently had a question about using the I2C library to create a Slave Device.  We realized there are a few details to be aware of and there is no packaged Slave example so this post will hopefully clear up any questions.

First of all, you need to make sure you are attaching your request interrupt using the "I2C Attach Request Interrupt" VI not "I2C Attach Receive Interrupt".  Since this is the Slave side, it only responds to requests sent by the Master, so attach request must is used.  Also be sure to set your slave address properly.

Slave-Device.pngImage Enlarger

 

In the interrupt handler you have attached, there are a couple ways to send data back to the Master.  There is an "I2C Write" polymorphic VI which has 3 methods: Write Byte, Write Array, and Write String.  When used in Slave Mode, it is important that the Write Mode is set to "Queue Only".  This inhibits the beginTransmission and endTramsission call from occurring in the Arduino library.  If beginTransmission is called, it automatically forces master mode within the Arduino Wire library.  This will cause the Slave to never respond if it is used in the Slave side interrupt handler.  Here is an example of the Slave side interrupt to return a byte of data to the Master.  Note that "Send Stop" must be set to True to release the bus after the Slave is done sending.

I2C-Requestor-Byte.pngImage Enlarger

 

However, for Write String (as of Compiler version 1.0.0.21) there is no Write Mode input and Write String automatically calls beginTransmission.  To get around this, the attached Arduino Wire library can be used which forces Slave mode when the Slave Address is set to 0.  Since the I2C write function sends data to the Slave Address specified (when used on the Master side) then it makes sense that the library should force Slave mode when the Slave address is undefined, or set to 0.  Here is an example of the Slave side interrupt to return a string of data to the Master.  Note that "Send Stop" must be set to True to release the bus after the Slave is done sending and the Slave Address is set to 0.

I2C-Requestor-String.pngImage Enlarger

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
5
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356