Oct 11, 2021
12:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 11, 2021
12:47 AM
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.
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.
- Tags:
- IFX
6 Replies
Oct 12, 2021
01:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 12, 2021
01:23 AM
/*
* 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
* 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
Oct 12, 2021
01:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 12, 2021
01:26 AM
I think the problem is that that callback function won't get called, but I don't know how to solve that.
Oct 12, 2021
10:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 12, 2021
10:01 PM
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
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
Oct 13, 2021
04:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 13, 2021
04:30 AM
This is my interrupt config
Oct 13, 2021
04:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 13, 2021
04:35 AM
#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
#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
Jan 26, 2022
11:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 26, 2022
11:01 AM
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