From 96ce4aa26eadf65b9e429aa480454cd9f2de28f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Erik=20D=C3=BCntzsch?= Date: Mon, 4 Mar 2024 17:40:47 +0100 Subject: [PATCH] added register readout --- Core/Inc/HTPA_32x32d.h | 3 ++- Core/Src/HTPA_32x32d.c | 38 +++++++++++++++++++++++++++++++------- Core/Src/main.c | 8 +++----- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Core/Inc/HTPA_32x32d.h b/Core/Inc/HTPA_32x32d.h index f058793..059efd0 100644 --- a/Core/Inc/HTPA_32x32d.h +++ b/Core/Inc/HTPA_32x32d.h @@ -28,8 +28,9 @@ typedef struct { } HTPA_Status; void HTPA_Init(I2C_HandleTypeDef *); -void HTPA_ReadBlock(uint8_t, uint8_t, uint16_t *[128]); +void HTPA_ReadBlock(uint8_t, uint8_t, uint8_t blockData[256]); void HTPA_WriteRegister(uint8_t, uint8_t); +uint8_t HTPA_ReadRegister(uint8_t register_address); HTPA_Status HTPA_GetStatus(void); diff --git a/Core/Src/HTPA_32x32d.c b/Core/Src/HTPA_32x32d.c index 327d44b..dfb2c94 100644 --- a/Core/Src/HTPA_32x32d.c +++ b/Core/Src/HTPA_32x32d.c @@ -79,14 +79,19 @@ void HTPA_Init(I2C_HandleTypeDef *hi2c){ * @param block: select block of array half (0-3) * @param *pData[128]: pointer to 128 word array for read data */ -void HTPA_ReadBlock(uint8_t array_half, uint8_t block, uint16_t *pData[256]){ +void HTPA_ReadBlock(uint8_t array_half, uint8_t block, uint8_t blockData[256]){ uint8_t config = 0; + uint8_t statusReg = 0; //config = (block << 4); // bit 5,4 block config |= 0x09; // bit 3 start | bit 1 wakeup HTPA_WriteRegister(HTPA_SENSOR_CONFIG, config); - HAL_Delay(100); // dauer??? + HAL_Delay(1000); // dauer??? // read status register: - HAL_I2C_Master_Receive(&i2c_handle, HTPA_SENSOR_ADDRESS, &htpa_statusReg, 1, I2C_MAX_DELAY); + statusReg = HTPA_ReadRegister(HTPA_SENSOR_STATUS); + HAL_Delay(100); + + + // tbc } @@ -103,9 +108,28 @@ void HTPA_WriteRegister(uint8_t register_address, uint8_t byte){ uint8_t i2c_data = register_address; uint8_t i2c_address = (HTPA_SENSOR_ADDRESS << 1); i2c_address &= 0xFE; // set read/write bit to write (0) - HAL_I2C_Master_Transmit(&i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY); + HAL_I2C_Master_Transmit(i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY); i2c_data = byte; - HAL_I2C_Master_Transmit(&i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY); + HAL_I2C_Master_Transmit(i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY); +} + +/** + * @brief Read single register + * + * description + * + * @param register_address: address of register + * @return +*/ +uint8_t HTPA_ReadRegister(uint8_t register_address){ + uint8_t i2c_data = register_address; + uint8_t i2c_address = (HTPA_SENSOR_ADDRESS << 1); + uint8_t i2c_rx = 0; + i2c_address &= 0xFE; // set read/write bit to write (0) + HAL_I2C_Master_Transmit(i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY); + i2c_address |= 0x01; // set read/write bit to write (1) + HAL_I2C_Master_Receive(i2c_handle, i2c_address, &i2c_rx, 1, I2C_MAX_DELAY); + return i2c_rx; } /** @@ -123,9 +147,9 @@ HTPA_Status HTPA_GetStatus(void){ uint8_t i2c_address = (HTPA_SENSOR_ADDRESS << 1); uint8_t i2c_readData = 0; i2c_address &= 0xFE; // set read/write bit 0 to write (0) - HAL_I2C_Master_Transmit(&i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY); + HAL_I2C_Master_Transmit(i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY); i2c_address |= 0x01; // set read/write bit 0 to read (1) - i2c_status = HAL_I2C_Master_Receive(&i2c_handle, i2c_address, &i2c_readData, 1, I2C_MAX_DELAY); + i2c_status = HAL_I2C_Master_Receive(i2c_handle, i2c_address, &i2c_readData, 1, I2C_MAX_DELAY); status_return.block = (i2c_readData >> 4) && 0xFC; status_return.vdd_meas = (i2c_readData >> 2) && 0xFE; status_return.blind = (i2c_readData >> 1) && 0xFE; diff --git a/Core/Src/main.c b/Core/Src/main.c index 246bc6b..c56a118 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -44,11 +44,8 @@ I2C_HandleTypeDef hi2c1; /* USER CODE BEGIN PV */ -<<<<<<< HEAD -HTPA_Status temp_status; -======= HTPA_Status htpa_status_test; ->>>>>>> afcf6b12b5d8a341020af122f3264c2701e1162e +uint8_t htpa_blockData[256]; /* USER CODE END PV */ @@ -106,9 +103,10 @@ int main(void) /* USER CODE BEGIN WHILE */ while (1) { - temp_status = HTPA_GetStatus(); htpa_status_test = HTPA_GetStatus(); HAL_Delay(1000); + HTPA_ReadBlock(1, 1, htpa_blockData); + HAL_Delay(1000); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */