XMC4700 I2c BME280

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User22854
Level 1
Level 1
Hello everyone,

has someone already experience in connecting a BME 280 with i2c to the XMC4700? I already tried to, but my board doesn't start to communicate with the sensor.

I already found this Thread https://www.infineonforums.com/threads/5402-I2C-Xmc4700-Relax-Kit but it doesn't work.
0 Likes
6 Replies
User22854
Level 1
Level 1
/*
* main.c
*
* Created on: 2021 Oct 12 09:29:59
* Author: LintlSebasti
*/




#include "DAVE.h" //Declarations from DAVE Code Generation (includes SFR declaration)

#include "bme280.h"
#include "stdio.h"
#include "math.h"

/**

* @brief main() - Application entry point
*
* Details of function

* This routine is the application entry point. It is invoked by the device startup code. It is responsible for
* invoking the APP initialization dispatcher routine - DAVE_Init() and hosting the place-holder for user application
* code.
*/

int32_t temp=0;
uint32_t press=0, hum=0;


void tx_callback_0(void)
{

}

/* Receive callback handling */
void rx_callback_0(void)
{
bme280_read(&temp, &press, &hum);
}

int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init(); /* Initialization of DAVE APPs */

if (status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}


/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{
float t, p, h;


bme280_init(0);

for (;;) {

bme280_read(&temp, &press, &hum);
for (int i = 500000; i > 0; i--) {};

t = (float)temp / 100.0;
p = (float)press / 10000.0;
h = (float)hum / 1024.0;
h = (1 - pow((p/1013.25), (1/5.255))) * (t + 273.15) / 0.0065;

}
}
}
This is my Code from the main.c
0 Likes
User22854
Level 1
Level 1
I think the problem is that that callback function won't get called, but I don't know how to solve that.
0 Likes
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked
Hi,

Will you be able to share more details about your project ? How the I2C is configured. Have you enabled and defined the call back function ?

Best Regards,
Vasanth
0 Likes
User22854
Level 1
Level 1
5468.attach
This is my interrupt config
0 Likes
User22854
Level 1
Level 1
#include
#include "i2c.h"

// Sensor definitions
#define SENSOR_WRITE_ADDRESS 0xBE
#define SENSOR_READ_ADDRESS 0xBF
#define SENSOR_RESET_ADDRESS 0x00
#define DELAY (500000)


#define device &I2C_MASTER_0

void delay(uint32_t counter)
{
volatile uint32_t cnt = counter;
while(--cnt);
}

int i2c_master_init(uint8_t device_number, uint8_t mode)
{

I2C_MASTER_Init(device);
delay(0xfffff);

}


int i2c_master_write(uint8_t device_number, uint32_t slave_addr, uint8_t data)
{
slave_addr = (slave_addr << 1);
I2C_MASTER_Init (device);
I2C_MASTER_Transmit (device,true, slave_addr, &data, 1,false);

delay(0xfffff);

return 0;
}

int i2c_master_read(uint8_t device_number, uint32_t slave_addr, uint8_t *data)
{

slave_addr=(slave_addr << 1) | (1 << 0);
I2C_MASTER_Init(device);
I2C_MASTER_Receive(device,true,slave_addr,data,1,true,true);

delay(0xfffff);

return 0;
}


int i2c_master_burst_write(uint8_t device_number, uint32_t slave_addr, uint8_t *data, uint16_t len)
{
slave_addr = (slave_addr << 1);
I2C_MASTER_Init (device);
I2C_MASTER_Transmit (device,true, slave_addr, data, len,false);

delay(0xfffff);

return 0;
}

int i2c_master_burst_read(uint8_t device_number, uint32_t slave_addr, uint8_t *data, uint16_t len)
{

slave_addr = (slave_addr << 1) | (1 << 0);
I2C_MASTER_Init(device);
I2C_MASTER_Receive(device,true,slave_addr,data,len,true,true);


delay(0xfffff);

return 0;
}




And this is the function which connects the BME280.h to the XMC4700
0 Likes
Aashita_R
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi @User22854 ,

1. In the app info of I2C MASTER, under the usage section is explained the interfacing of HMI board with XMC 4500 board. The usage of callbacks is shown in the context. Can you please go through the app info of I2C MASTER app in DAVE? You can go to the app info for I2C MASTER here : Open DAVE-> Go to APP Dependency -> Add New APP -> Communications->General-> I2C Master -> Usage.

2. Another resource you can refer is theI2C Master Slave code example which explains the basic functioning of I2C communication protocol in XMC 4700 device.

Please go through above and let us know in case of further clarifications.

Best Regards,

Aashita

0 Likes