Aug 14, 2017
12:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 14, 2017
12:23 PM
I am facing a problem. I have a couple of XMC4500 Relax Kit development board. I also have 2 nos. of self-contained Si7021, BME280 and AT24C256 board/module.
I have connected my modules with the XMC4500 Relax Kit via Dupont cables (20 cm length). All modules are interfaced with MCU via IIC bus. I am using a common bus (IIC) for interfacing all modules.
When I interface Si7021 module the program works seamlessly but the same program does not work for BME280 and AT24C256 modules. After sending Start Condition (including start address) I am not getting an acknowledgment from the slave.
The Protocol Status Register has the following value :
PSR_IICMode -> 0x3434
For purpose of debugging have commented all operational code except for I2C communication but I receive the same status from PSR.
I have checked slave address and it is proper. The catch is the same modules work seamlessly when interfaced with Raspberry Pi 3 for which I wrote an I2C PROGRAM.
I am confused how did PSR register the following events :
Code :
I have connected my modules with the XMC4500 Relax Kit via Dupont cables (20 cm length). All modules are interfaced with MCU via IIC bus. I am using a common bus (IIC) for interfacing all modules.
When I interface Si7021 module the program works seamlessly but the same program does not work for BME280 and AT24C256 modules. After sending Start Condition (including start address) I am not getting an acknowledgment from the slave.
The Protocol Status Register has the following value :
PSR_IICMode -> 0x3434
- Start Condition Received
- Stop Condition Received
- Non-Acknowledge Received
- Receiver Start Indication Flag
- Transmit Shift Indication Flag
- Transmit Buffer Indication Flag
For purpose of debugging have commented all operational code except for I2C communication but I receive the same status from PSR.
I have checked slave address and it is proper. The catch is the same modules work seamlessly when interfaced with Raspberry Pi 3 for which I wrote an I2C PROGRAM.
I am confused how did PSR register the following events :
- Stop Condition Received
- Receiver Start Indication Flag
Code :
void initI2C(void)
{
XMC_GPIO_CONFIG_t i2c_sda =
{
.mode = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT1,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE
};
XMC_GPIO_CONFIG_t i2c_scl =
{
.mode = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT1,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE
};
XMC_I2C_CH_CONFIG_t i2c_cfg =
{
.baudrate = 50000U,
};
XMC_I2C_CH_Init(SENSOR_I2C_CHANNEL, &i2c_cfg);
XMC_I2C_CH_SetInputSource(SENSOR_I2C_CHANNEL, XMC_I2C_CH_INPUT_SDA, USIC2_C0_DX0_P5_0);
XMC_I2C_CH_SetInputSource(SENSOR_I2C_CHANNEL, XMC_I2C_CH_INPUT_SCL, USIC2_C0_DX1_P5_2);
XMC_I2C_CH_EnableEvent(SENSOR_I2C_CHANNEL, XMC_I2C_CH_STATUS_FLAG_TRANSMIT_BUFFER_INDICATION);
XMC_I2C_CH_EnableEvent(SENSOR_I2C_CHANNEL, XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION);
XMC_I2C_CH_EnableEvent(SENSOR_I2C_CHANNEL, XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
XMC_I2C_CH_SetInterruptNodePointer(SENSOR_I2C_CHANNEL, XMC_I2C_CH_INTERRUPT_NODE_POINTER_TRANSMIT_BUFFER);
XMC_I2C_CH_SetInterruptNodePointer(SENSOR_I2C_CHANNEL, XMC_I2C_CH_INTERRUPT_NODE_POINTER_RECEIVE);
XMC_I2C_CH_SetInterruptNodePointer(SENSOR_I2C_CHANNEL, XMC_I2C_CH_INTERRUPT_NODE_POINTER_ALTERNATE_RECEIVE);
XMC_I2C_CH_Start(SENSOR_I2C_CHANNEL);
XMC_GPIO_Init(SCL_PIN, &i2c_scl);
XMC_GPIO_Init(SDA_PIN, &i2c_sda);
/*Configuring priority and enabling NVIC IRQ for the defined Service Request line number */
NVIC_SetPriority(USIC2_0_IRQn, 61U);
NVIC_EnableIRQ(USIC2_0_IRQn);
deviceType = DEVICE_NONE; //No Selected Device
operationType = OPERATION_NONE; //No Selected Operation
currentState = MASTER_READY; //Default Start State
previousState = MASTER_READY; //Default Start State
i2cBusBusy = false; //Initialize I2C bus State/Condition to free
}
void i2c_irq(void)
{
if(deviceType == DEVICE_BME280)
bme280_irq();
else if(deviceType == DEVICE_AT24C256)
at24c256_irq();
}
void bme280_startConfigRegisterWrite(void)
{
i2cBusBusy = true;
deviceType = DEVICE_BME280;
operationType = BME280_CONFIG_WRITE;
calibReg0 = false;
previousState = MASTER_READY;
currentState = MASTER_START_SEND;
bme280_configRegisterWriteComplete = false;
XMC_I2C_CH_MasterStart(SENSOR_I2C_CHANNEL, BME280_ADDRESS, XMC_I2C_CH_CMD_WRITE);
//I get negative acknowledgement after the above statement
}
bool bme280_configRegisterWrite(void)
{
bool opValid = false;
unsigned int flag = XMC_I2C_CH_GetStatusFlag(SENSOR_I2C_CHANNEL);
if((flag & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED))
{
previousState = currentState;
if(currentState == MASTER_START_SEND)
currentState = MASTER_CMD_SEND;
else if(currentState == MASTER_CMD_SEND)
currentState = MASTER_DATA_SEND;
else if(currentState == MASTER_DATA_SEND)
currentState = MASTER_STOP_SEND;
opValid = true;
XMC_I2C_CH_ClearStatusFlag(SENSOR_I2C_CHANNEL, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);
}
else if(flag & XMC_I2C_CH_STATUS_FLAG_NACK_RECEIVED)
{
//Only nack gets executed
opValid = false;
XMC_I2C_CH_ClearStatusFlag(SENSOR_I2C_CHANNEL, XMC_I2C_CH_STATUS_FLAG_NACK_RECEIVED);
}
if(!opValid)
return false;
switch(currentState)
{
case MASTER_CMD_SEND :
XMC_I2C_CH_MasterTransmit(SENSOR_I2C_CHANNEL, BME280_CONFIG);
//The “config” register sets the rate, filter and interface options of the device.
//Writes to the “config” register in normal mode may be ignored. In sleep mode writes are not ignored.
break;
case MASTER_DATA_SEND :
//Set Stand By Time : 125 mS and Filter Coefficient : 16
//uint8_t data = (BME280_TIME_125 << BME280_STAND_BY_POS) | (BME280_FILTER_16 << BME280_FILTER_POS);
XMC_I2C_CH_MasterTransmit(SENSOR_I2C_CHANNEL, (BME280_TIME_125 << BME280_STAND_BY_POS) | (BME280_FILTER_16 << BME280_FILTER_POS));
//Once program is proved delete variable 'data' and move the entire equation in place of second parameter
break;
case MASTER_STOP_SEND :
XMC_I2C_CH_MasterStop(SENSOR_I2C_CHANNEL);
bme280_configRegisterWriteComplete = true;
i2cBusBusy = false;
break;
}
return true;
}
- Tags:
- IFX
0 Replies