How to work with I2C 'Two Wire Interface' Devices!

preview_player
Показать описание
Code shown in the video:

Compass: HMC6352
EEPROM: 24LC256
RTC: DS1307


Thanks to all the Patrons for dropping a few bucks in the tip jar to help make these videos happen!

For inquiries or design services:
Рекомендации по теме
Комментарии
Автор

"...bought a component claiming to be a simple 2-wire interface..." => Bullseye.
"Don't want to know how to build I2C, just communicate..." => Bullseye.
Awesome tutorial => Bullseye.

Can't wait to get my astonishingly cheap/powerful IMU working! Gyro + 3axis acc + mag + barometer = programming challenge foolhardily accepted.

Thanks man! Couldn't do it without Y-tuters like yourself.

smaniac
Автор

@MazlumOguz yea, I agree, but I don't have any SPI devices, when I get something, a video will be made

Kevindarrah
Автор

@WakeUpWolfgang yea, it took a while to make, hopefully it helps!

Kevindarrah
Автор

got it from futurlec, thanks! glad it helped!!

Kevindarrah
Автор

that would be cool, to actually bit bang your way through the I2C communication. Not sure if I'll ever have the time to do something like that.. we'll see

Kevindarrah
Автор

@TheSchetsofiel69 absolutely! I should've showed that! You can setup another mcu as a slave device. See the arduino reference help

Kevindarrah
Автор

yea, it just gets a little confusing, especially when you're looking at timing diagrams using bits

Kevindarrah
Автор

@friendsonearth I'm not sure... I've never seen that happen.

Kevindarrah
Автор

In addition to the MSB, LSB version, you can also do something like:

data = low | high << 8;

This shifts the high bits up 8 bits and ORs ( | ) the low bits in, giving you the result you want.

Simple, easy to read and understandable. :)

AlanClegg
Автор

Nice explanation, thank you.
I really need to get my head around this I2C stuff, that cleared away a lot of the mud.

michaelhawthorne
Автор

Another note... the way that the RTC uses the 4 bits for "10 seconds" and 4 bits for "1 seconds" sets you up perfectly if you are using hex. ;-)

since 55 seconds would be 0x55 .. and 18 seconds would be 0x18 (note that 4 bits (a nibble) is one hex character.

For the other items (AM, PM, etc) you would probably want to use a struct{} to build and set it up easily.

AlanClegg
Автор

I've been listening and not paying much attention (the Adafruit librariies for Arduino make I2C so easy, see my video from February), then I heard "I didn't have to do this for loop" at 19:30 and started to look at your code ... Oh, man, you make the original K&R ("The C Programming Language") formatting look like The Ultimate In Structured Programming!

Please, people,
Indent your loop contents,
Just a little, please!

TranscendentBen
Автор

@friendsonearth don't know what you mean, the delay() is arduino, the real time clock is the device ds1307, and there is also a clock signal line for the devices, so...?

Kevindarrah
Автор

You just have to know that for the 4 lower bits the values 1, 2, 4, 8 are and the upper bits are 10, 20, 40, 80. So you can roughly see what the value is in an instant

Elixz
Автор

cool, make sure you let me if it works out

Kevindarrah
Автор

Thanks for the video! My Icom 706 uses I2C, and I would like to be able to build devices to communicate to it. This gave me some good insight.

NA
Автор

@JurriaanPetersen haha, I knew somebody was gonna be mad about all my smack talk...

Kevindarrah
Автор

I guess it would be rude to ask about a demonstration on this "bit banging", but do you know any videos that explain this to great detail? The problem I was having was identifying the device, and I finally found a sketch for arduino to do it, but I didn't understand how it worked. For my part this kind of insight is very helpful. Great videos btw, just subscribed! :)

SirArghPirate
Автор

Thanks Kevin very clear on what could be an intimidating topic for us newbies. I found it very helpfull - muchos gracias

timjackson
Автор

Hi this is very helpful video.
I had trying to get a simple communication between Arduino Diecimila and PIC24 through I2C. Its almost 3 months completed in search of communicating these devises.
I am in a serious need of help I need a simple communication between pic24fj256ga110 a 100 pin device with Arduino, both of these devise are individual powered supplied and for pic I am using MPLAB IDE.

rmknh