H753_CPP_I2C_DS3231_RTC_01 1.0
STM32H753 DS3231 real-time clock over I2C, with an AT24C32 EEPROM marker that stops the clock being set twice, built on the STM32_DS3231 and STM32_AT24C32 libraries
Loading...
Searching...
No Matches
AT24C32.h
Go to the documentation of this file.
1/*
2 * AT24C32.h
3 *
4 * STM32 HAL driver for the Atmel/Microchip AT24C32 32 Kbit (4096 byte) I2C EEPROM,
5 * as found on the common ZS-042 DS3231 breakout module.
6 *
7 * Written from the AT24C32D datasheet (DS20006047A): device address, 16-bit word
8 * address, 32-byte page write, acknowledge polling and sequential read. It is an
9 * independent implementation, not a port of anyone else's library.
10 *
11 * Created on: Oct 7, 2026
12 * Author: johng
13 */
14
15#ifndef STM32_AT24C32_AT24C32_H_
16#define STM32_AT24C32_AT24C32_H_
17
18#include "main.h"
19#include <stdint.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
79#define AT24C32_SIZE_BYTES 4096U
80
82#define AT24C32_PAGE_SIZE 32U
83
85#define AT24C32_MAX_ADDRESS_PINS 7U
86
88#define AT24C32_DEFAULT_MAX_ATTEMPTS 3U
89
91#define AT24C32_I2C_TIMEOUT_MS 100U
92
97#define AT24C32_WRITE_TIMEOUT_MS 20U
98
106
108typedef struct {
109 I2C_HandleTypeDef *hi2c;
110 uint16_t deviceAddress;
111 uint8_t maxAttempts;
112 HAL_StatusTypeDef lastStatus;
113} AT24C32_t;
114
115AT24C32_Status_t at24c32Init(AT24C32_t *dev, I2C_HandleTypeDef *hi2c, uint8_t addressPins, uint8_t maxAttempts);
116AT24C32_Status_t at24c32Read(AT24C32_t *dev, uint16_t memAddress, uint8_t *data, uint16_t length);
117AT24C32_Status_t at24c32Write(AT24C32_t *dev, uint16_t memAddress, const uint8_t *data, uint16_t length);
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif /* STM32_AT24C32_AT24C32_H_ */
AT24C32_Status_t at24c32Init(AT24C32_t *dev, I2C_HandleTypeDef *hi2c, uint8_t addressPins, uint8_t maxAttempts)
Set up a driver handle and check that an AT24C32 answers on the bus.
Definition AT24C32.c:131
AT24C32_Status_t at24c32Read(AT24C32_t *dev, uint16_t memAddress, uint8_t *data, uint16_t length)
Read bytes from the memory.
Definition AT24C32.c:166
AT24C32_Status_t
Definition AT24C32.h:100
@ AT24C32_ERR_NOT_FOUND
Definition AT24C32.h:103
@ AT24C32_ERR_PARAM
Definition AT24C32.h:102
@ AT24C32_OK
Definition AT24C32.h:101
@ AT24C32_ERR_BUS
Definition AT24C32.h:104
AT24C32_Status_t at24c32Write(AT24C32_t *dev, uint16_t memAddress, const uint8_t *data, uint16_t length)
Write bytes to the memory.
Definition AT24C32.c:192
: Header for main.c file. This file contains the common defines of the application.
HAL_StatusTypeDef lastStatus
Definition AT24C32.h:112
I2C_HandleTypeDef * hi2c
Definition AT24C32.h:109
uint16_t deviceAddress
Definition AT24C32.h:110
uint8_t maxAttempts
Definition AT24C32.h:111