Using SERCOM I2C for SMBus on SAMDA1

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

Looking for examples how to use the SERCOM I2C driver on SAMDA1 device for SMBus comm.  Specifically, reading through app notes and example code from Atmel studies it not entirely clear how to get the driver to read 16-bit words from a SMBus 1.1 and SBDat 1.1 compliant device.   I can consistently perform Read Byte Protocol using the "i2c_master_write_wait_no_stop" and "i2c_master_read_packet_wait" functions as outlined in the SERCOM I2C app note.  But I want to perform a Read Word Protocol since registers are 16-bit.  Experimenting with the different function calls hasn't yielded success.  I presume there is a simple solution...I just am not seeing it.  

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

For clarity I should note that I expected "i2c_master_read_packet_wait" to return a 16-bit word but after the first byte is received from the slave, the master transmits a NACK/ACKn then a stop bit.  This could be interpreted as a Read Byte Protocol or something is broken?

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

c_hansen wrote:
I expected "i2c_master_read_packet_wait" to return a 16-bit word

On what basis do you expect that?

 

Can you point to the function's documentation ...

 

EDIT

 

Something like this, perhaps: 

 

http://asf.atmel.com/docs/latest/sam0.applications.edbg_i2c_info_interface.samr21_xplained_pro/html/group__asfdoc__sam0__sercom__i2c__group.html#ga238a755f972b9c3287131cda5fc25725

 

Atmel wrote:

enum status_code i2c_master_read_packet_wait ( struct i2c_master_module *const  module,
    struct i2c_master_packet *const  packet 
  )    

Reads data packet from slave.

Reads a data packet from the specified slave address on the I2C bus and sends a stop condition when finished.

Note

This will stall the device from any other operation. For interrupt-driven operation, see i2c_master_read_packet_job.

Parameters

[in,out] module Pointer to software module struct
[in,out] packet Pointer to I2C packet to transfer

Returns

Status of reading packet.

 

 

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...
Last Edited: Mon. Aug 20, 2018 - 02:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Documentation isnt clear on how these functions behave so I made an assumption.   I took the time to understand this I2C driver better by stepping through the code and now see what is going on (image that!).   In the end I defined DATA_LENGTH of 1 for a write command packet and DATA_LENGTH of 2 for read commands packet which now returns 2 bytes when I preform a single register read of my smart battery.  The 2 functions I used; " i2c_master_write_packet_wait_no_stop" and "i2c_master_read_packet_wait"