minimum setup for twi

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



I'm fairly familiar with programming ST M4-based microprocessors but I'm new to Atmel and ASF and am starting a project on a custom ATSAM4S8C-based board. I've hit-and-missed the basic clock and IO setup and have a fair bit of my firmware running, but I'm having a very hard time getting the I2C periperhals to function reliably.


My startup code for TWI0 which I pieced together from various sources looks like this:


if(true) { /* TWI0 */
    twi_master_options_t twi_master_options= {
        .master_clk  = 0, // sysclk_get_cpu_hz(),    //! MCK for TWI.
        .speed= 2500,    //! The baud rate of the TWI bus. // Hz
        .chip = 0,    //! The desired address.
        .smbus = 0 //! SMBUS mode (set 1 to use SMBUS quick command, otherwise don't).

    gpio_configure_pin(PIO_PA3_IDX, PIO_PERIPH_A | PIO_DEFAULT);
    gpio_configure_pin(PIO_PA4_IDX, PIO_PERIPH_A | PIO_DEFAULT);
    twi_master_setup(TWI0, &twi_master_options);

with a similar section for TWI1. 


My drivers for the different peripherals pretty much all start with a call to twi_probe(), then follow up with calls to twi_master_read() and twi_master_write(). Sometimes they work, although never reliably, and sometimes the call to the initial twi_probe() hangs.


So, given that I don't have a userboard.h or .c, what is the minimum setup required to get the twi calls to function correctly? Also, am I better off using the twi service or driver?


Thank you all




Last Edited: Fri. Apr 16, 2021 - 03:57 PM