Solved: SAM C21 I2C with PCF8574

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

Hi everyone!

 

I am trying to use port expander PCF8574 attached to SAM C21 using Atmel Start.

But anything I try I get NACK on sending

 

 uint8_t ab;
 int32_t res;
 struct io_descriptor *I2C_0_io;

 res=i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io);
 res=i2c_m_sync_enable(&I2C_0);
 res=i2c_m_sync_set_slaveaddr(&I2C_0, 0x4e, I2C_M_SEVEN);
 ab=0xff;
 res=io_write(I2C_0_io, &ab, 1);

The PCF8574 ist hooked up to PA16 and PA17  with 10k pullups and everything seems to be set up correctly in Atmel Start.

I am not very familar with I2C ... please help!

 

Christian

Last Edited: Fri. Jan 26, 2018 - 09:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you get an ack on the adres?

or does that already give an error?

If so you have the wrong slave address

that can be 7 or 8 bit interpretation and depending on the connected adres selectors on the 8574 a different address to.

then if you have a 'A' (IIRC it was an A) veriant of the device you again have a different address.

 

first make sure you get an ack on the adres, before that there is no point in trying to send any data.....

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

arrrrrg .... it was that 7 bit thing ...

I simply took the address according to the datasheet where the read/write bit was included. Taking this address SHR 1 (adr>>1) did the Magic!

Thank you for bringin me to the right lead!

 

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

chm wrote:
arrrrrg .... it was that 7 bit thing ...

Yes - a very common problem: https://www.avrfreaks.net/comment...

 

the address according to the datasheet where the read/write bit was included.

Strictly, that's wrong - but very common

 

frown

 

https://www.avrfreaks.net/comment...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...