07-01-2020 04:20 PM
Hello,
started a new Projekt which contains the Sensordata from the BHI160b. I am using the BHI160 Shuttle Board. My Microcontroller is an STM32L053R8 which i will use to read out the sensordata. I started to follow the driver Porting guide to adapt the Functions to my Platform. At first i created a New Projekt with my STM32 init code and also included the BHy MCU driver. At the beginning i removed the lines in the file bhy_support.c
#include "FreeRTOS.h"
#include "task.h"
extern int8_t sensor_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
extern int8_t sensor_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
extern void trace_log(const char *fmt, ...);
After that i tried build the target Files in i have an error:
..\Drivers\BHI160b_driver\inc\BHy_support.h(59): error: #5: cannot open source input file "twi.h": No such file or directory
Because the twi.h is a platform specific library for Atmel i also removed this line from file bhy_support.h.
After this change i tried to rebuild again and now i have a lot of undefined identifiers :
..\Drivers\BHI160b_driver\inc\bhy_uc_driver_types.h(252): error: #20: identifier "uint8_t" is undefined uint8_t sensor_id;
Even the Porting guide says that in this case, the bhy.h should be modified to define the following fixed-width types:
s8, s16, s32, u8, u16, u32
I looked in this file and i am not sure how to exactly implement these types. Does anyone have an example for that?
Also i should implement specific sensor_i2c_write() sensor_i2c_read() functions. This 2 functions have to be in bhy_support.c?
Because there are no existing i2c functions just the declaration like this:
extern int8_t sensor_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
extern int8_t sensor_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
Are there any example codes that has an HAL i2c connection to this sensor?
Thx for helping!
Solved! Go to Solution.
07-02-2020 10:21 AM
Hello Belaya,
The following is a I2C read and write example on STM32F401, you could refer it.
uint8_t GTXBuffer[256];
int8_t SensorAPI_I2Cx_Read(uint8_t slave_address7, uint8_t subaddress, uint8_t *pBuffer, uint16_t ReadNumbr)
{
uint16_t DevAddress = slave_address7 << 1;
// send register address
HAL_I2C_Master_Transmit(&I2C_HANDLE, DevAddress, &subaddress, 1, BUS_TIMEOUT);
HAL_I2C_Master_Receive(&I2C_HANDLE, DevAddress, pBuffer, ReadNumbr, BUS_TIMEOUT);
return 0;
}
int8_t SensorAPI_I2Cx_Write(uint8_t slave_address7, uint8_t subaddress, uint8_t *pBuffer, uint16_t WriteNumbr)
{
uint16_t DevAddress = slave_address7 << 1;
GTXBuffer[0] = subaddress;
memcpy(>XBuffer[1], pBuffer, WriteNumbr);
// send register address
HAL_I2C_Master_Transmit(&I2C_HANDLE, DevAddress, GTXBuffer, WriteNumbr+1, BUS_TIMEOUT);
return 0;
}
07-02-2020 01:03 PM
Thanks for that sample code! I can actually use it like that. But how about the problem with the datatypes defines in bhy.h? Do you know how to define them?
07-02-2020 02:08 PM
Is there a way that you can show me a sample main.c code to choose a sensor for my stm32?
07-03-2020 03:40 AM
Hello Belaya,
STM32 is 32 bit machine, data type define will be the following code in bhy.h.
/*signed integer types*/
typedef signed char s8;/**< used for signed 8bit */
typedef signed short int s16;/**< used for signed 16bit */
typedef signed int s32;/**< used for signed 32bit */
/*unsigned integer types*/
typedef unsigned char u8;/**< used for unsigned 8bit */
typedef unsigned short int u16;/**< used for unsigned 16bit */
typedef unsigned int u32;/**< used for unsigned 32bit */