Hi guys,
i looked through this forum a lot and also looked up all the internet to get some advise for my problem. In case anyone finds the proper article, then i apologize that i opened a new thread.
So, I came across to program my own ATMEGA 32 off the scratch some time ago. I really like the arduino, play around with it a lot but very quickly reach its limits, especially when it comes to IDE.
Alright, my problem is know, that I do not succeed in communicating with the IMU (pololu.com/catalog/product/1268) by my I2C interface.
To ensure that the IMU is working I attached it to the arduino and saw the data coming properly, so I am pretty sure the IMU is able to work.
Now I use the I2C library that is widely spread from pete fleury (see attachment). Together with this library, I am trying to talk to the IMU (gyro in first place).
My sequence for programming looks like this (not a code extract):
i2c_init()
i2c_start(LGD320_WRITE) //means to set ID and write Bit
i2c_write(LGD320_CTRL_REG) // to turn on the IMU i need to set the ctrl register first
i2c_write(0x08) //setting the PD bit to one
i2c_stop()
//now i want to read the Who am i register
i2c_start(LGD320_WRITE)
i2c_write(LGD320_WHO_AM_I)
i2c_repstart(LGD320_READ) //as now I want to read data (see datasheet for sequence)
data = i2c_receive_byte() //that should give me the data?
i2c_nak() (to stop the i2c communication)
I would like to know if you think that at least this sequencing is correct? the arduino example doesnt give too much insight…
Then unfortunately immediately as I start the program it hangs at the start condition (i2c_start(Address) ) and the TWI Status Register is not getting an acknowledge:
if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) )
this is actually not succeeding…
Hardware wise I introduced the Pull Up Resistors properly, wires are properly connected, so I guess I am fine.
Has anyone already tried this with an ATMEGA32 in C only?
Any good suggestion what might be the issue.
I use an external crystal with 12MHz, SCL_Clock is set to 100kHz. Any limitation that I oversaw?
Thanks for your help in advance.
i2cmaster.zip (23 KB)