TWI with SAM4SXPlained pro

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everybody,

 

Recently, I bought a SAM4SXPlained pro to start in the microcontrollers world :).  After running a LED blinking program, I am involved now with TWI communication. I am try to communicate with a I2C temperature sensor ( LC74 of Microchip) but I can't and I would need some help. I am using for that the header EXT1 y the pins 11(TWD0) y 12 (TWCLK0)

 

This is the code

 

#include <asf.h>
#include <twi.h>

int main (void)
{
    board_init();

    /* Initialize the SAM system */
    SystemInit(); 

   sysclk_init();
   pmc_enable_periph_clk(ID_TWI0);

   
   
  uint8_t buffer;
    
   twi_options_t opt = {
    .speed = 100000,
    .master_clk =sysclk_get_cpu_hz(),

   };

   twi_packet_t packet = {
      .addr = 0x00,
      .addr_length = 1,
      .buffer = (void*)buffer,
      .chip = 0x48,//address of the slave
      .length = 8
   };

 

    while (1)
    {
        
           twi_enable_master_mode(TWI0);
           twi_master_init(TWI0,&opt);
           twi_master_read(TWI0,&packet);

    

    
    }

    
    
}

Is the code right?

Apparently I am not receiving the NANK of the register status in the function twi_master_read but I don't know why. I think that the connexion between the LC74 and the board is ok

 

Thank you for you help