I2C example uses same USART as USB serial com? | 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 4 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
I2C example uses same USART as USB serial com?
September 24, 2015
4:42 pm
Avatar
Jim.UF
Member
Forum Posts: 17
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

I’m running the I2C Master/Slave example on two Megas, which have four USARTS. 

I see the code to ‘talk’ to the Serial Monitor is not in I2C Slave.vi , it’s in the referenced vi, I2C Receive Interrupt.vi. The implication is the I2C com and the USB serial com are using the same USART (0). 

Is this correct? If so, I need some pointers on how to separate them; I don’t see where the I2C Master.vi code is selecting USART 0.
Jim

September 24, 2015
5:20 pm
Avatar
Steffan
Admin
Forum Posts: 305
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Jim,

Are you confusing I2C with UART?  They are totally separate physical interfaces.  I2C uses pins SDA and SCL.  UART uses TX0 and RX0 (for the PC USB serial port).  TX/RX 1,2,3 are additional UART ports available on the Mega but not related to I2C at all.  The example you are referring to is just showing that the data is received in the I2C receive interrupt (from SDA/SCL) of the slave by spitting the data back out the USB serial port to the PC.  Am I missing your question?

Steffan

September 24, 2015
6:51 pm
Avatar
Jim.UF
Member
Forum Posts: 17
Member Since:
September 24, 2015
sp_UserOfflineSmall Offline

Steffan,
You are so right! Even having used I2C in the past and ‘knowing’ there is a data line and a CLOCK line, had it fixed in my mind that it’s an asynchronous protocol needing a UART. Duuuuh … 

So to ‘refine’ my questions: In I2C Slave.vi:
- I2C Attach Receive Interrupt.vi calls the ref vi (I2C Receive interrupt .vi in this case), presumably when a complete message has been received (clock line goes ‘off’?).
- I2C Receive interrupt .vi is where I’d do something different with the received data, getting it out of the vi with global variables if necessary?
Jim

September 24, 2015
7:58 pm
Avatar
Steffan
Admin
Forum Posts: 305
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Ok no worries.

You are mostly correct.  Attach Receive Interrupt.vi initializes the I2C Receive interrupt with the Callback address of the I2C Receive Interrupt.vi meaning that when an I2C message is received (not just clock line going "off" but a full message of N bytes), this VI executes.  Inside this VI you can call I2C Read All Bytes.vi to get all bytes that were received when the interrupt went off.

You are correct, you can pass any relevant info back to your main VI using global variables.

Forum Timezone: UTC 0

Most Users Ever Online: 33

Currently Online:
3 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

John: 18

RTSLVU: 15

Dan6077: 11

Member Stats:

Guest Posters: 0

Members: 80

Moderators: 0

Admins: 3

Forum Stats:

Groups: 1

Forums: 2

Topics: 58

Posts: 289

Newest Members: Travlissah, viktorIcera, HowardClouG, Dianecet, Produktnaodchudzaniex

Administrators: geadmin: 5, filipealtoe: 35, Steffan: 89