Regarding TWI_MASTER example code in ATtiny817

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

Hi,

 

I interfaced io1 Xplained pro with tiny817 under master mode to receive the temperature value from the sensor and it worked fine with the example code,,similarly i interfaced the HDC1000 clickboard with the same example.c code generated from tiny817,,but the behaviour seems different. The example code in short is pasted below

 

void I2C_0_do_transfer(uint8_t adr, uint8_t *data, uint8_t size)

{

transfer_descriptor_t d = {data, size};

while (!I2C_0_open(slave_adr))

; // sit here until we get the bus..

// This callback specifies what to do after the first write operation has completed

// The parameters to the callback are bundled together in the aggregate data type d.

I2C_0_set_data_complete_callback((void *)I2C_0_read_handler, &d);

// If we get an address NACK, then try again by sending SLA+W

I2C_0_set_address_nack_callback((void *)i2c_cb_restart_write, NULL);

// Transmit one byte

I2C_0_set_buffer((void *)&adr, 1);

// Start a Write operation

I2C_0_master_operation(false);

while (I2C_BUSY == I2C_0_close())

; // sit here until the entire chained operation has finished

}

 

if you witness the above code in bold the callback (void *)i2c_cb_restart_write works fine in case of io1 but in case of clickboard interface it doesn't but the same part if i modify to (void *)i2c_cb_restart_read i could get the expected temperature output....What may be the reason??

gud day

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

venkatrajpravin wrote:
the behaviour seems different

 

In what way(s), exactly, is it "different"?

 

  • What, exactly, were you expecting to happen?
  • What, exactly, actually happened?
  • What testing/debugging/investigation have you done to account for the difference?

 

How to properly post source code: 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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

venkatrajpravin wrote:
the HDC1000 clickboard

The what?

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

i was expecting to read the temperature value using the HDC1000 (http://www.ti.com/lit/ds/symlink...) sensor by providing the corresponding slave address and the pointer address to the example.c file in tiny817 without modifying the inbuilt API and i expected to receive the temperature value in the MDATA reg. as it worked fine with io1 Xplained pro temperature sensor.

gud day

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • What, exactly, actually happened?......what actually happened was 
    #include <atmel_start.h>
    #include <i2c_types.h>
    #include <utils/atomic.h>
    
    #define slave_adr 0x40
    #define slave_reg_adr 0x0
    
    /** Structure passed into read_handler to describe the actions to be performed by the handler */
    typedef struct {
    	uint8_t *data;
    	uint8_t  size;
    } transfer_descriptor_t;
    
    /** This callback is called when the initial write of the pointer register has finished.
        This callback controls the second phase of the I2C transaction, the read of the
        targeted register after a REPEATED START.
    */
    i2c_operations_t I2C_0_read_handler(void *d)
    {
    	transfer_descriptor_t *desc = (transfer_descriptor_t *)d;
    	I2C_0_set_buffer((void *)desc->data, desc->size);
    	// Set callback to terminate transfer and send STOP after read is complete
    	I2C_0_set_data_complete_callback(i2c_cb_return_stop, NULL);
    	return i2c_restart_read; // Send REPEATED START before read
    }
    
    /** Performs the following transfer sequence:
    1. Send SLA+W, Data1
    2. Send RepeatedStart, SLA+R, Read Data1, Read Data2
    3. Send Stop
    
    This transfer sequence is typically done to first write to the slave the address in
    the slave to read from, thereafter to read N bytes from this address.
    */
    void I2C_0_do_transfer(uint8_t adr, uint8_t *data, uint8_t size)
    {
    	transfer_descriptor_t d = {data, size};
    	while (!I2C_0_open(slave_adr))
    		; // sit here until we get the bus..
    	// This callback specifies what to do after the first write operation has completed
    	// The parameters to the callback are bundled together in the aggregate data type d.
    	I2C_0_set_data_complete_callback((void *)I2C_0_read_handler, &d);
    	// If we get an address NACK, then try again by sending SLA+W
    	I2C_0_set_address_nack_callback((void *)i2c_cb_restart_write, NULL);
    	// Transmit one byte
    	I2C_0_set_buffer((void *)&adr, 1);
    	// Start a Write operation
    	I2C_0_master_operation(false);
    	while (I2C_BUSY == I2C_0_close())
    		; // sit here until the entire chained operation has finished
    }
    

    to the above code io1 was working as expected and in case of hdc1000 it worked fine after modifying 

    I2C_0_set_address_nack_callback((void *)i2c_cb_restart_read, NULL);

 

Testing/debugging/investigation :

 

On debugging in the actual case i set a breakpoint under the callback where the data was actually receiving but the breakpoint was achieved and in the second case it was not so  

gud day

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

You do realise that it's an entirely different sensor on the IO XPlained board ?

 

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

ya,,,thats true,,but i hope the code in example.c is developed to support any type of interface that can act as slave i.e. it should work irrespective of the type of slave ,,,am i right??

gud day

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

venkatrajpravin wrote:
am i right??

No.

 

It will show you the basics of how to address a slave, send bytes to it, and read bytes from it - but you will have to modify it to send the correct bytes to it, in the correct order, for the operations you require...

 

 

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

so it is like the example code in tiny817 is just a reference and not the actual code for the operation to be carried upon,,if this is the reason then yes on modification i could actually achieve the output

gud day

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

Thanks awneil for your support:)

gud day

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

You said the example code was for the IO1 Xplained-Pro - so that's what it's for!

 

If you want to use it for something else, you will have to modify it accordingly.

 

I'm sure TI supply example code for their sensors.

 

You still haven't said what you meant by, "the HDC1000 clickboard",  but I guess you mean this: https://shop.mikroe.com/hdc1000-... - there are examples linked from that page.

 

 

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

the example code was not specifically for IO1 Xplained pro,,on creating project for ATtiny817 in start.atmel.com,,you could find an example.c file on code generation,,i was talking about this infactExample file in ATtiny817

gud day

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

Hello venkatrajpravin. I've been looking all over for example code to use the ATtiny817 Xplained Pro board and IO1 accessory board together. Can you tell me where you found that code you posted?

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

That is a two year old thread. The original posters are not likely still around. But, from the  #include in the previous message, it appears to be part of START.

 

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

ka7ehk wrote:

That is a two year old thread. The original posters are not likely still around. But, from the  #include in the previous message, it appears to be part of START.

 

Jim

 

Thank you Jim. I've spent hours in Atmel 7 and the START examples and just haven't found the example. It's frustrating. My Atmel 7 software shows both the ATtiny817 Xplained Pro board and the IO1 board as connected. But no example code pops up or is findable among the START examples. Itype in "I2C" as a search term and the field showing examples goes blank.

John

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

BTW, 50 years ago I was WN8DRC.

John

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

Try a search for "TWI" - that is Atmel's name for I2C. Not sure which is used on these newer chip.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

At this point it appears that there simply is no canned example for the Attiny817 Xplained Pro with the IO1 board plugged into it. There is a video series developing sensors using the SAM L21. Odd.

 

John