TWI problem

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi you all,

I use the atmega328p as master.
But I have some problem with I2C, it is working but not very well. I measure a temperature ussing a LM75A.

First I send all the settings to the slave that is going good, but after that it is ackting strange.

I send a start condition, than the adres of the slave with the metion that it has to send the data (only 1 byte).
This is also done and after that I repeat this cycle.
Than the strange things begin.

Sometimes it stops after the first time reading the temperature(it is the right value).
Sometimes it is running but the result is always the same even if the temperature is changed.

I think I do someting wrong with sending a NACK at the end, but I don't know what. Maybe one of you can help me?

The piece of the code that I included is the one that I use to read the temperature.
thanks, Patrick

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Before looking at any code you need to make sure your hardware is ok.

What are you using for the board? What is the value of the I2C pullup resistor you use?
Is the clock really running at the speed you think it is running? (may affect the I2C bus speed)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Before looking at any code you need to make sure your hardware is ok.

What are you using for the board? What is the value of the I2C pullup resistor you use?
Is the clock really running at the speed you think it is running? (may affect the I2C bus speed)

Thanks for the reply,

At the moment I use a arduino UNO board.
My clock is 400kHz and I use 2K pull-up resitors.
My clock is a nice square wave.

I tried all kind of things and looked at examples but it looks like I don't do anything strange.
Once I setup the registers for the LM75A. I start in the main loop and read the temp register.
This is working once and after that it stops.
But I let it jump back to main and then it must read the temperature again. This is not happening.
What happens is that the SCL is going high and SDA is going low or high this is not constant.
After a reset it reads again but only once.

Hope someone can point me in the right direction.
Patrick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just looked at the code, is that all you have? Where are you initialising the TWI?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here are the files that I work with now.

At the end of the initmaster, I send a NACK. But when I look at the SDA patern I don't see a rising on the SDA but a spike can this cause the problem? And if so what do I have to do to prevent this?

Thanks

Attachment(s):