add testing function for 24AA02E48 EEPROM module

This commit is contained in:
ІО-23 Шмуляр Олег 2025-03-09 14:12:20 +02:00
parent 5785093138
commit 5f23a03009
3 changed files with 106 additions and 4 deletions

1
Core/Inc/24AA02E48.h Normal file
View File

@ -0,0 +1 @@
void EEPROM_24AA02E48_run_test(void);

98
Core/Src/24AA02E48.c Normal file
View File

@ -0,0 +1,98 @@
#include "main.h"
#include "lcd.h"
#include "24AA02E48.h"
extern I2C_HandleTypeDef hi2c1;
void EEPROM_24AA02E48_run_test(void)
{
DISPLAY_CLEAR;
display_write_data_seq("24AA02E48 EEPROM");
HAL_StatusTypeDef op_result;
size_t err_count = 0;
// write the Address Pointer register
uint8_t data_buffer[13];
data_buffer[12] = '\0';
data_buffer[0] = 0x00;
for (size_t t = 0; t < 5; t++) {
op_result = HAL_I2C_Master_Transmit(&hi2c1, 0xA0, data_buffer, 1, 2000);
if (op_result) {
err_count++;
DISPLAY_CLEAR;
display_write_data_seq("24AA02E48 EEPROM");
DISPLAY_SET_CURSOR(1, 0);
display_write_data_seq("W ");
display_write_data_byte('1' + t);
display_write_data_seq("/5 ");
switch (op_result) {
case HAL_ERROR:
display_write_data_seq("ERROR");
break;
case HAL_BUSY:
display_write_data_seq("BUSY");
break;
case HAL_TIMEOUT:
display_write_data_seq("TIMEOUT");
break;
}
HAL_Delay(2000);
} else {
break;
}
}
for (size_t t = 0; t < 5; t++) {
op_result = HAL_I2C_Master_Receive(&hi2c1, 0xA1, data_buffer, 12, 2000);
if (op_result) {
err_count++;
DISPLAY_CLEAR;
display_write_data_seq("24AA02E48 EEPROM");
DISPLAY_SET_CURSOR(1, 0);
display_write_data_seq("R ");
display_write_data_byte('1' + t);
display_write_data_seq("/5 ");
switch (op_result) {
case HAL_ERROR:
display_write_data_seq("ERROR");
break;
case HAL_BUSY:
display_write_data_seq("BUSY");
break;
case HAL_TIMEOUT:
display_write_data_seq("TIMEOUT");
break;
}
HAL_Delay(2000);
} else {
break;
}
}
DISPLAY_CLEAR;
display_write_data_seq("24AA02E48 EEPROM");
if (err_count) {
DISPLAY_SET_CURSOR(1, 0);
display_write_data_byte('0' + err_count / 10 % 10);
display_write_data_byte('0' + err_count % 10);
display_write_data_seq('E ');
display_write_data_seq(data_buffer);
} else {
DISPLAY_SET_CURSOR(1, 1);
display_write_data_seq("OK ");
display_write_data_seq(data_buffer);
}
}

View File

@ -26,6 +26,7 @@
#include "lcd.h"
#include "external_temp.h"
#include "PCA9685.h"
#include "24AA02E48.h"
/* USER CODE END Includes */
@ -57,16 +58,18 @@ I2C_HandleTypeDef hi2c1;
void ((*executors[])(void)) = {
external_temp_show_celsius,
external_temp_show_fahrenheit,
PCA9685_run_test
PCA9685_run_test,
EEPROM_24AA02E48_run_test
};
void ((*cleanup_functions[])(void)) = {
NULL,
NULL,
PCA9685_cleanup
PCA9685_cleanup,
NULL
};
int delay_between_runs[] = {250, 250, -1};
int delay_between_runs[] = {250, 250, -1, -1};
size_t current_executor_id = 0;
@ -209,7 +212,7 @@ void button_init_and_test(void)
void switch_to_next_test(void)
{
current_executor_id += 1;
current_executor_id %= 3;
current_executor_id %= 4;
}
/* USER CODE END 0 */