added status and block readout

This commit is contained in:
Tim-Erik Düntzsch 2023-03-24 23:23:49 +01:00
parent f2294c896c
commit 745d2a79a7
5 changed files with 55 additions and 16 deletions

View File

@ -8,9 +8,18 @@
#ifndef INC_HTPA_32X32D_H_
#define INC_HTPA_32X32D_H_
typedef struct {
uint8_t block;
uint8_t vdd_meas;
uint8_t blind;
uint8_t eoc;
}HTPA_Status;
void HTPA_Init(I2C_HandleTypeDef *);
void HTPA_ReadBlock(uint8_t, uint8_t, uint16_t *[128]);
void HTPA_WriteRegister(uint8_t, uint8_t);
HTPA_Status HTPA_GetStatus(void);
#endif /* INC_HTPA_32X32D_H_ */

View File

@ -31,6 +31,7 @@
I2C_HandleTypeDef i2c_handle;
HAL_StatusTypeDef i2c_return; // error handling maybe?
uint16_t blockData[128];
void HTPA_Init(I2C_HandleTypeDef *hi2c){
@ -44,13 +45,35 @@ void HTPA_Init(I2C_HandleTypeDef *hi2c){
HTPA_WriteRegister(HTPA_SENSOR_TRIM_5, 0x0C);
HTPA_WriteRegister(HTPA_SENSOR_TRIM_6, 0x0C);
HTPA_WriteRegister(HTPA_SENSOR_TRIM_7, 0x88);
//HTPA_WriteRegister(HTPA_SENSOR_CONFIG, 0x09); // Wakeup | Start
}
void HTPA_ReadBlock(uint8_t array_half, uint8_t block, uint16_t *pData[128]){
uint8_t config = (block << 4); // bit 5,4 block
config |= 0x09; // bit 3 start | bit 1 wakeup
HTPA_WriteRegister(HTPA_SENSOR_CONFIG, config);
}
void HTPA_WriteRegister(uint8_t register_address, uint8_t byte){
uint8_t i2c_data = register_adress;
HAL_I2C_Master_Transmit(&i2c_handle, HTPA_SENSOR_ADDRESS, &i2c_data, 1, I2C_MAX_DELAY);
uint8_t i2c_data = register_address;
uint8_t i2c_address = (HTPA_SENSOR_ADDRESS << 1);
i2c_address |= 0x00; // set read/write bit to write (0)
HAL_I2C_Master_Transmit(&i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY);
i2c_data = byte;
HAL_I2C_Master_Transmit(&i2c_handle, HTPA_SENSOR_ADDRESS, &i2c_data, 1, I2C_MAX_DELAY);
HAL_I2C_Master_Transmit(&i2c_handle, i2c_address, &i2c_data, 1, I2C_MAX_DELAY);
}
HTPA_Status HTPA_GetStatus(void){
HTPA_Status status_return;
uint8_t i2c_data = HTPA_SENSOR_STATUS;
uint8_t i2c_address = (HTPA_SENSOR_ADDRESS << 1);
uint8_t i2c_readData = 0;
i2c_address |= 0x00; // 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 read (1)
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;
status_return.eoc = i2c_readData && 0xFE;
return status_return;
}

Binary file not shown.

View File

@ -1,2 +1,4 @@
../Core/Src/HTPA_32x32d.c:37:6:HTPA_Init 16 static
../Core/Src/HTPA_32x32d.c:43:6:HTPA_Wakeup 16 static
../Core/Src/HTPA_32x32d.c:50:6:HTPA_ReadBlock 24 static
../Core/Src/HTPA_32x32d.c:56:6:HTPA_WriteRegister 40 static
../Core/Src/HTPA_32x32d.c:65:13:HTPA_GetStatus 40 static

View File

@ -75,16 +75,21 @@ Discarded input sections
0x0000000000000000 0x54 ./Core/Src/HTPA_32x32d.o
.bss.i2c_return
0x0000000000000000 0x1 ./Core/Src/HTPA_32x32d.o
.bss.i2c_data 0x0000000000000000 0x1 ./Core/Src/HTPA_32x32d.o
.bss.blockData
0x0000000000000000 0x100 ./Core/Src/HTPA_32x32d.o
.text.HTPA_Init
0x0000000000000000 0x28 ./Core/Src/HTPA_32x32d.o
.text.HTPA_Wakeup
0x0000000000000000 0x44 ./Core/Src/HTPA_32x32d.o
.debug_info 0x0000000000000000 0x6be ./Core/Src/HTPA_32x32d.o
.debug_abbrev 0x0000000000000000 0x16a ./Core/Src/HTPA_32x32d.o
0x0000000000000000 0x64 ./Core/Src/HTPA_32x32d.o
.text.HTPA_ReadBlock
0x0000000000000000 0x40 ./Core/Src/HTPA_32x32d.o
.text.HTPA_WriteRegister
0x0000000000000000 0x70 ./Core/Src/HTPA_32x32d.o
.text.HTPA_GetStatus
0x0000000000000000 0xfc ./Core/Src/HTPA_32x32d.o
.debug_info 0x0000000000000000 0x83a ./Core/Src/HTPA_32x32d.o
.debug_abbrev 0x0000000000000000 0x1be ./Core/Src/HTPA_32x32d.o
.debug_aranges
0x0000000000000000 0x28 ./Core/Src/HTPA_32x32d.o
.debug_ranges 0x0000000000000000 0x18 ./Core/Src/HTPA_32x32d.o
0x0000000000000000 0x38 ./Core/Src/HTPA_32x32d.o
.debug_ranges 0x0000000000000000 0x28 ./Core/Src/HTPA_32x32d.o
.debug_macro 0x0000000000000000 0x20c ./Core/Src/HTPA_32x32d.o
.debug_macro 0x0000000000000000 0xa4e ./Core/Src/HTPA_32x32d.o
.debug_macro 0x0000000000000000 0x12d ./Core/Src/HTPA_32x32d.o
@ -123,10 +128,10 @@ Discarded input sections
.debug_macro 0x0000000000000000 0x4c ./Core/Src/HTPA_32x32d.o
.debug_macro 0x0000000000000000 0x15b ./Core/Src/HTPA_32x32d.o
.debug_macro 0x0000000000000000 0x12e ./Core/Src/HTPA_32x32d.o
.debug_line 0x0000000000000000 0x6bf ./Core/Src/HTPA_32x32d.o
.debug_str 0x0000000000000000 0x8239f ./Core/Src/HTPA_32x32d.o
.debug_line 0x0000000000000000 0x729 ./Core/Src/HTPA_32x32d.o
.debug_str 0x0000000000000000 0x8245b ./Core/Src/HTPA_32x32d.o
.comment 0x0000000000000000 0x51 ./Core/Src/HTPA_32x32d.o
.debug_frame 0x0000000000000000 0x50 ./Core/Src/HTPA_32x32d.o
.debug_frame 0x0000000000000000 0x94 ./Core/Src/HTPA_32x32d.o
.ARM.attributes
0x0000000000000000 0x2c ./Core/Src/HTPA_32x32d.o
.group 0x0000000000000000 0xc ./Core/Src/main.o