ATSAMD20J18 I2C Communication frame problem

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

Hello,

I'm using HAL libraries for I2C communication. Below are the commands I used.

 

i2c_m_sync_set_slaveaddr(&I2C_0,DAC_mcp4728_ID,I2C_M_SEVEN);   - for setting slave ID

i2c_m_sync_cmd_write(&I2C_0,DAC_mcp4728_VREFWRITE,TxFrame,1);  -  for sending register command and data.

 

Here TxFrame is an array so no & used.

 

But, only the slave ID is getting transmitted and not the next register address and frame.

Can anyone guide me what is wrong here?

 

P.S - this is the same I2C slave I have used previously with STM32. And its working fine there with same device ID and register address.

This topic has a solution.

Hrishikesh

Last Edited: Tue. Apr 6, 2021 - 09:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dixit.hrishikesh26 wrote:
its working fine there with same device ID

Note that software libraries[1] are notoriously inconsistent in how they require the Slave address:

  • Just the 7 address bits, right justified in a byte (ie, in bits 0-6);
  • Just the 7 address bits, right justified in a byte (ie, in bits 1-7);
  • The 7 address bit plus the R/W bit in a byte;
  • who knows what else?!

 

https://www.avrfreaks.net/commen...

 

So have you looked on the wires (with a scope or analyser) to see what's actually happening?

 

EDIT

 

[1] As the linked post says, it's not just software libraries - hardware manufacturer's documentation is just as bad.

 

frown

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: Wed. Mar 17, 2021 - 09:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

So have you looked on the wires (with a scope or analyser) to see what's actually happening?

yes i've analyzed, the slave is acknowledging the device address but the next input register and data is not getting transmitted.

Hrishikesh

Last Edited: Thu. Feb 25, 2021 - 12:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My device address id 0xC8. Which is 8bit. Do I need to convert it to 7 bits?

Hrishikesh

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

I2C addresses are defined to be 7 bits; there is no such thing as an "8-bit" address - again, see #2.

 

But, if the Slave is ACKing, then you must have the address correct.

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, the slave isn't acknowledging. 

Hrishikesh

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

In #3, dixit.hrishikesh26 wrote:
the slave is acknowledging the device address

In #6, dixit.hrishikesh26 wrote:
No, the slave isn't acknowledging. 

So you need to go back to whatever you had in #3 - where at least you were getting an ACK.

 

How about sharing your analyser traces - so that everyone can see what's going on?

See Tip #1 in my signature for how to post images

 

In #1, dixit.hrishikesh26 wrote:
this is the same I2C slave I have used previously with STM32. 

So compare what's happening in that working case with what's happening in this case.

 

I'm using HAL libraries for I2C communication

What "HAL libraries", exactly, are you using? Give a link.

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What "HAL libraries", exactly, are you using? Give a link.

 https://ww1.microchip.com/downlo...

 

Please refer this link for Libraries.

ow about sharing your analyser traces - so that everyone can see what's going on?

 

Hrishikesh

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

Surely your scope has a proper screen capture facility?

 

Does that trace show the working version, or the non-working?

 

Does the scope have an I2C decode facility?

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does that trace show the working version, or the non-working?

Its non working. Blue line is clock pulse. The clock is getting stopped when it doesn't get acknowledgement bit from slave. 

 

Does the scope have an I2C decode facility?

I've cross verified the frame according to the frame sent. Its not exactly same as what is sent. 

Hrishikesh

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

dixit.hrishikesh26 wrote:
 https://ww1.microchip.com/downlo...

So ASF4, then.

 

As that document says, that's intended to be used with START - so have you used START to create your project?

 

If not, how are you sure that you have correctly configured & initialised everything?

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If not, how are you sure that you have correctly configured & initialised everything?

Actually, there are two slaves present on the same bus. One is working properly, other is not.

Same hardware configuration is working with STM32. So I designed in reference to that.

Hrishikesh

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

dixit.hrishikesh26 wrote:
Same hardware configuration is working with STM32.

So, again, look at what happens on the I2C lines in that case - and compare that to what's happening in your non-working case.

 

EDIT

 

Remember that the slave device neither knows nor cares what microcontroller you use - all it sees is what's happening on the I2C lines.

 

EDIT 2

 

dixit.hrishikesh26 wrote:
Actually, there are two slaves present on the same bus

As a test, it might be worth taking the other slave off - just to ensure that it's not some interaction of the 2 slaves with the SAM-D ...

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: Wed. Mar 17, 2021 - 10:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, again, look at what happens on the I2C lines in that case - and compare that to what's happening in your non-working case.

slave isn't acknowledging the address. SO, the full frame not getting transmitted. 

Is there any configuration I'm missing out or like that ?

Hrishikesh

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

dixit.hrishikesh26 wrote:
slave isn't acknowledging the address.

Is that what you're seeing on your scope?

 

If it's not ACKing, then it's not seeing the correct address; again, check the scope trace - is the address correct?

 

Are you sure the slave is properly powered, and enabled, and the physical connection is correct and working? 

 

Again, have you compared the working case (STM32) with the non-working case (SAM-D) ?

 

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: Wed. Mar 17, 2021 - 11:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is that what you're seeing on your scope?

Yes. Slave do not send ack bit .

 

If it's not ACKing, then it's not seeing the correct address; again, check the scope trace - is the address correct?

Yes it is. 

 

Again, have you compared the working case (STM32) with the non-working case (SAM-D) ?

Yes sir I've compared . I'm sitting taking both the hardware and doing comparision. 

Hrishikesh

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

dixit.hrishikesh26 wrote:
Slave do not send ack

So what happened between #3 (when you said it did ACK) and #6 (where you said it doesn't)

 

I've compared

So what does the comparison tell you?

 

Again:

I wrote:
Are you sure the slave is properly powered, and enabled, and the physical connection is correct and working? 

 

Think about all possible reasons why a slave might not ACK; eg,

 

  • The slave is not powered
  • The slave is asleep/disabled
  • The slave's I2C interface is disabled
  • The slave is broken
  • The connection to the slave is wrong/broken
  • The slave is not configured for the address you think
  • Something else on the bus is interfering
  • The bus is at the wrong voltage and/or speed for the slave
  • etc, etc, ...

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your continuous support sir, my problem is solved. I've carefully gone through the document and needed to change device address using EEPROM of DAC. Thanks

Hrishikesh

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dixit.hrishikesh26 wrote:
my problem is solved.

That's good to hear - and thanks for feeding back the solution.

 

Now please mark the solution - see Tip #5 in my signature, below:

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...