コード例 #1
0
void i2c_eeprom_slave_init(void) {
	uint64_t uid = uid_get_uid64();

	memcpy(eeprom.memory, &uid, sizeof(uint64_t));

	eeprom.offset = 0;
	eeprom.acquire = 0;
	eeprom.page = 0;

	const Pin twi_pins[] = {PINS_TWI_STACK};

	// Configure TWI pins
	PIO_Configure(twi_pins, PIO_LISTSIZE(twi_pins));

	// Enable TWI peripheral clock
	PMC->PMC_PCER0 = 1 << ID_TWI1;

	// Configure TWI interrupts
	NVIC_DisableIRQ(TWI1_IRQn);
	NVIC_ClearPendingIRQ(TWI1_IRQn);
	NVIC_SetPriority(TWI1_IRQn, PRIORITY_EEPROM_SLAVE_TWI1);
	NVIC_EnableIRQ(TWI1_IRQn);

    // Configure TWI as slave, with address I2C_EEPROM_SLAVE_ADDRESS
    TWI_ConfigureSlave(TWI_STACK, I2C_EEPROM_SLAVE_ADDRESS);

    // Enable TWI interrupt
    TWI_EnableIt(TWI_STACK, TWI_IER_SVACC);
}
コード例 #2
0
ファイル: Wire.cpp プロジェクト: ektor5/Arduino
void TwoWire::begin(uint8_t address) {
	if (onBeginCallback)
		onBeginCallback();

	// Disable PDC channel
	twi->TWI_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;

	TWI_ConfigureSlave(twi, address);
	status = SLAVE_IDLE;
	TWI_EnableIt(twi, TWI_IER_SVACC);
	//| TWI_IER_RXRDY | TWI_IER_TXRDY	| TWI_IER_TXCOMP);
}