cancel
Showing results for 
Search instead for 
Did you mean: 

XMC

User22854
New Contributor
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
5 Replies
User22854
New Contributor
/*
* 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
New Contributor
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
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
New Contributor
5468.attach
This is my interrupt config
0 Likes
User22854
New Contributor
#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
Top labels