2015-07-29 02:29 AM
Hello,
I need to make my STM32F072 communicate with a HIH sensor through I2C.I want to use HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive. For exemple if I just need to generate a write condition bit may I use it even if txbuffer is a uint8 type? #sensor #i2c #i2c #hal2015-07-29 05:56 AM
Hi pwdusid,
You can create a new project with STM32CubeMx 4.9.0 and try to be inspired by the set example underSTM32Cube_FW_F0_V1.3.0\Projects\STM32F072B-Discovery\Examples\I2C.
-Shahrzad-
2015-07-29 06:33 AM
I have already tried und I know how to manege HAL I2C library to send byte, word but I am wondering if I can just send a sequence like :
Start-A6-A5-A4-A3-A2-A1-A0-WriteBite(==0). with A5...A0 slave address.2015-07-30 08:17 AM
2015-07-30 10:03 AM
The OP is defining an addressing bit pattern sent over the wire, not the data that transits afterward.
The Transmit and Receive should dictate the low order bit.It might help to specify exactly what part you're trying to talk too. Cite a data sheet.And show what code you have now, the're not that may ways to talk to I2C devices, so one of more example I2C driver should be sufficient to mash together a working example.ST needs to focus on providing clear, concise, and robust examples of as many use cases as possible.2015-07-31 05:23 AM
Ok I haven't been clear sorry.
I have attached the datasheet of sensor I want to communicate with. I am trying to send the ''I2C Measurement Request'' where no data are required to be sent and I want to useHAL_I2C_Master_Transmit function but it is not possible to send empty buffer. ________________ Attachments : I2C_Comms_HumidIcon_.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzO0&d=%2Fa%2F0X0000000bMk%2Fc7DD4pJZymGJI9Fe4s9VFXTSbKs8DN6pCv1aHY3WUWc&asPdf=false2015-07-31 05:42 AM
And for now i have something very simple:
DB.h
#define TXBUFFERSIZE (COUNTOF(aTxBuffer) - 1)
DB.c
#define I2C_ADDRESS 0x4E // 6 LSBs of Slave address ('x27' as mentionne on attached datasheet) + write bit
#define I2C_TIMING 0x00B21847 //400k
uint8_t aTxBuffer[]=''BONJOUR''; // I don't need to send this data
void DB_I2C_Init(void){
I2cHandle.Instance = I2Cx;
I2cHandle.Init.Timing = I2C_TIMING;
I2cHandle.Init.OwnAddress1 = 0;
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
I2cHandle.Init.OwnAddress2 = 0;
I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
if(HAL_I2C_Init(&I2cHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
}
void DB_I2C_Measurement_Request_Honey(void){
HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t *)aTxBuffer, TXBUFFERSIZE, 1000);
}
2015-08-17 07:59 AM
Hi pwdusid,
Regarding the needs to manage I2C device with data size null, please try the fix in attachment ( line 501 and line 984) Goal of this fix is to remove size null condition only for these 2 interfaces : - HAL_I2C_Master_Transmit() - HAL_I2C_Master_Transmit_IT() For other interface, no specific needs to remove null condition. -Shahrzad- ________________ Attachments : stm32f0xx_hal_i2c.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzUm&d=%2Fa%2F0X0000000bMl%2F1FmRSildVTEn0N5nydq.CVB1wLV1munSCPKUbwXCYIQ&asPdf=false