added register readout

This commit is contained in:
Tim-Erik Düntzsch 2024-03-04 17:40:47 +01:00
parent 7f9e1bac35
commit 96ce4aa26e
3 changed files with 36 additions and 13 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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 */