int main(void) { _delay_ms(1000); ENABLE_DEBUG_LEDS; LED3_ON; wait_for_push(); twiInit(); // init_rgb_leds(); // init_optical_interrupt(); //test twi functions uint8_t commands[] = {0x1B, 0x5B, 'j'}; // reset lcd cursor and clear screen uint8_t data[] = {'H', 'E', 'L', 'L', 'O'}; twiMasterWrite(LCD_WRITE_ADDR, commands, 3); twiMasterWrite(LCD_WRITE_ADDR, data, 5); // test memory write to DS1307 uint8_t send_with_address[] = {0x08, 'h', 'e', 'l', 'l','o'}; twiMasterWrite(RTC_WRITE_ADDR, send_with_address, 6); uint8_t receive_buffer[] = {0, 0, 0, 0, 0}; twiMasterReadFromLoc(RTC_READ_ADDR, RTC_WRITE_ADDR, 0x08, receive_buffer, 5); twiMasterWrite(LCD_WRITE_ADDR, receive_buffer, 1); while(1) { // do nothing } }
//Initialize the i2c communication and set the gyro to full scale range and 100 Hz update rate void cITG3200::begin(void) { sbi(PORTD, GYRO_ADO); //Set the gyro pin high to select 0xD2 as gyro address twiInit(80000); //Init. SCL speed to 50 kHz //Set internal clock to 1kHz with 42Hz LPF and Full Scale to 3 for proper operation write(DLPF_FS, DLPF_FS_SEL_0|DLPF_FS_SEL_1|DLPF_CFG_0); //Set sample rate divider for 100 Hz operation write(SMPLRT_DIV, 9); //Fsample = Fint / (divider + 1) where Fint is 1kHz //Setup the interrupt to trigger when new data is ready. write(INT_CFG, INT_CFG_RAW_RDY_EN | INT_CFG_ITG_RDY_EN); //Select X gyro PLL for clock source write(PWR_MGM, PWR_MGM_CLK_SEL_0); }
/** * Setup TWI */ void twi_setup(void) { gpio_enable_module_pin(TWI_SCL, AVR32_TWI_SCL_0_0_FUNCTION); gpio_enable_module_pin(TWI_DATA, AVR32_TWI_SDA_0_0_FUNCTION); twiInit(); }