/* * Initializes I2C0 */ void i2c_init() { // Initialize DMA timer for use in transfer delays dtim0_init(); // Configure GPIO port AS for SCL and SDA MCF_GPIO_PASPAR |= MCF_GPIO_PASPAR_SCL0_SCL0; MCF_GPIO_PASPAR |= MCF_GPIO_PASPAR_SDA0_SDA0; // Do we need data direction as output? /*MCF_GPIO_DDRAS |= MCF_GPIO_DDRAS_DDRAS0; MCF_GPIO_DDRAS |= MCF_GPIO_DDRAS_DDRAS1;*/ // Write the I2C board address MCF_I2C0_I2ADR |= MCF_I2C_I2ADR_ADR(I2C_ADDR); // Write the i2c clock rate. f_i2c = 80Mhz / divider // divider = 80Mhz / 0.1 Mhz = 800. Closest divider in Table 29.2 896 for 89.29Khz, IC = 0x3A MCF_I2C0_I2FDR |= MCF_I2C_I2FDR_IC(0x3A); // Reset to slave-receiver mode i2c_reset(); // If the bus is busy b/c a slave is transmitting, generate a stop bit when switching // from master-recviver back to slave-receiver if(MCF_I2C0_I2SR & MCF_I2C_I2SR_IBB) { MCF_I2C0_I2CR = 0x00; // Board is slave-receiver, i2c disabled, interrupts disabled MCF_I2C0_I2CR = 0xA0; // Board is master-receiver, i2c enabled, interrupts, disabled uint8_t dummy = MCF_I2C0_I2DR; // Dummy read from slave which is transmitting MCF_I2C0_I2SR = 0x00; // Clear arbitration lost flag, clear i2c interrupt request flag MCF_I2C0_I2CR = 0x00; // Board is slave-receiver, i2c disabled, interrupts disabled MCF_I2C0_I2CR = 0x80; // Enable I2C module } }
void fst_nunchuk_init(){ dtim0_init(); i2c_init(); //100 kHz }