2023-09-12 03:13 AM
Hello to everyone. I am trying to see the data via I2C with the capacitive sensor (FDC2214-Q1),
but I see the values I have assigned as 0 in live experiment.
I'm sure about the hardware part. I would be happy if you help.
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define FDC2214_I2C_ADDR_0 0x2A // Address is 0x2A (default) if 0x2B (high) //
#define FDC2214_I2C_ADDR_1 0x2B
#define FDC2214_DEVICE_ID 0x7F
#define FDC2214_DATA_CH0_LSB 0x01
#define FDC2214_DRIVE_CH0 0x1E
#define FDC2214_DATA_CH0_MSB 0x00
#define FDC2214_DATA_CH0 0x00
static char value_str[10];
uint32_t value = 0;
uint16_t lsb_buffer = 0;
uint16_t msb_buffer = 0;
uint8_t *lsb_buffer_ptr = (uint8_t *)&lsb_buffer;
uint8_t *msb_buffer_ptr = (uint8_t *)&msb_buffer;
//HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_I2C_Mem_Read(&hi2c1, FDC2214_I2C_ADDR_0, FDC2214_DATA_CH0, 1, msb_buffer_ptr, 1, HAL_MAX_DELAY);
HAL_I2C_Mem_Read(&hi2c1, FDC2214_I2C_ADDR_0, FDC2214_DATA_CH0_LSB, 1, lsb_buffer_ptr, 1, HAL_MAX_DELAY);
value = value | lsb_buffer; // 0000 0000 | 0000 XXXX = 0000 XXXX VALUE lsb'sini doldurdum.
msb_buffer = msb_buffer & 0x0FFF; // msb_buffer'ın ilk 4 bitini 0 ladım. Datasheet'e göre 12 biti lazım. // Gelen ilk degeri 0 dışında bir şey görüyorum
value = (msb_buffer << 12) | value; // msb_buffer'ı value'nun MSB kısmına kaydırdım ve orlayarak MSB kısmını doldurdum. 0000 XXXX | 0XXX 0000 = 0XXX XXXX
sprintf(value_str, "%ld", value);
// USART üzerinden veriyi gönder
HAL_UART_Transmit(&huart1, (uint8_t *) value_str, sizeof(value_str), HAL_MAX_DELAY);
while (1)
2023-09-12 03:57 AM - edited 2023-09-12 03:57 AM
Hello @MDaya.2
I suggest you to double check your device id, your i2c address and the validity of the data provided by your sensor.
Else I suggest you to debug your code to get the source of error.
Best regards.
II
2023-09-12 06:08 AM
HAL expects a left-shifted address, so 0x54 or 0x56 for this chip.
Always use HAL_I2C_IsDeviceReady to verify the chip is responding before trying other I2C functions.