Tue. Jan 28th, 2020

EFM32 – I2C for Telecommunications Layout TD1204/ TD1208

A great way to broaden Telecommunications Layout system is to utilize I2C to link exterior tools. As an instance I needed to include an additional Analog to Digital converter. I ’ m making use of a MCP3021 Ax gadget. This I2C chip simply return a 10 little bits worth each time you send out a READ at the anticipated address. This article consists of the TD1204 code to set up I2C and also obtain the information back

Right here is the resource code:

 #include << efm32 h> > #include << em_cmu. h> > #include << em_rmu. h> > #include << em_i2c. h> >// Configure required clock to have I2C functioning CMU_ClockEnable( cmuClock_GPIO, real); CMU_ClockEnable( cmuClock_I2C0, real);// Configure I/O pins for functioning as I2C - Result Open Up Drainpipe GPIO_PinModeSet( SCL_PORT, SCL_BIT, gpioModeWiredAnd,1); GPIO_PinModeSet( SDA_PORT, SDA_BIT, gpioModeWiredAnd,1); I2C0->> COURSE = I2C_ROUTE_SDAPEN|I2C_ROUTE_SCLPEN|_ I2C_ROUTE_LOCATION_LOC0;// Init the I2C with default param 100 KHz I2C_Init_TypeDef i2cInit = I2C_INIT_DEFAULT; I2C_Init( I2C0, && i2cInit);// Plan for a read of 2 bytes I2C_TransferSeq_TypeDef i2cTransfert; uint8_t worths[2] = {0,0}; i2cTransfert.addr = MCP3021 _ ADR_LOW;// Chip address << < < 1 i2cTransfert.flags = I2C_FLAG_READ;// READ Procedure i2cTransfert.buf[0] information = worths;// barrier i2cTransfert.buf[0] len = 2;// Check out 2 bytes as the gadget is 16 b// Begin I2C checked out int _ standing = I2C_TransferInit( I2C0, && i2cTransfert); while (_ standing == i2cTransferInProgress) {_ standing = I2C_Transfer( I2C0);}// Worths have actually been obtained! Condition needs to be 0 tfp_printf(" A - D0 %d D0 %d S %d/r/n", worths[0], worths[1], _ standing);

In instance you require to carry out a WRITE_WRITE command or WRITE_READ command to set/read interior register, you need to fill up the i2cTransfert framework a various means:

 worths[0] = _ REGISTER_ADDRESS; worths[1] = _ REGISTER_VALUE; i2cTransfert.addr = I2C_ADDR; i2cTransfert.flags = I2C_FLAG_WRITE_WRITE; i2cTransfert.buf[0] len = 1; i2cTransfert.buf[0] information = && worths[0]; i2cTransfert.buf[1] len = 1; i2cTransfert.buf[1] information = && worths[1]; _ standing = I2C_TransferInit( I2C0, && i2cTransfert); while (_ standing == i2cTransferInProgress) {_ standing = I2C_Transfer( I2C0);} 

You suggest you intend to move 2 bytes: both of them remain in WRITE setting. The initial one is the address, the 2nd one is the worth to establish. If you require to COMPOSE 2 registers you can alter buf[1] len for 2.

When you require to COMPOSE after that CHECK OUT a register, usage I2C_FLAG_WRITE_READ, the register to READ remains in buf[0] and also the outcome of the read will certainly remain in the buf[1]