|
stm32-async-1wire 3.2.0
Non-blocking 1-Wire master for STM32 with DS18B20 temperature and DS2431 EEPROM drivers
|
Non-blocking DS2431 1 kbit EEPROM driver for STM32. More...
Go to the source code of this file.
Macros | |
| #define | DS2431_FAMILY_CODE 0x2D |
| DS2431 1-Wire family code (LSB of the 64-bit ROM address). | |
| #define | DS2431_BITS_PER_BYTE 8 |
| Standard 8 bits per byte. | |
| #define | DS2431_ROM_BYTES 8 |
| Number of bytes in a device ROM address. | |
| #define | DS2431_EEPROM_SIZE 128 |
| DS2431 EEPROM size in bytes (1 kbit). | |
| #define | DS2431_PAGE_SIZE 32 |
| DS2431 EEPROM page size in bytes (4 pages of 32 bytes). | |
| #define | DS2431_PAGE_COUNT (DS2431_EEPROM_SIZE / DS2431_PAGE_SIZE) |
| Number of EEPROM pages. | |
| #define | DS2431_SCRATCH_SIZE 8 |
| DS2431 scratchpad size in bytes (one EEPROM block). | |
| #define | DS2431_SCRATCH_FRAME (DS2431_SCRATCH_SIZE + 3) |
| Maximum length of the Read Scratchpad reply frame in bytes. | |
| #define | DS2431_SCRATCH_FRAME_CRC (DS2431_SCRATCH_FRAME + 2) |
| Maximum wire length of the Read Scratchpad reply in bytes, CRC included. | |
| #define | DS2431_READ_MEMORY 0xF0 |
| DS2431 Read Memory command. | |
| #define | DS2431_WRITE_SCRATCHPAD 0x0F |
| DS2431 Write Scratchpad command. | |
| #define | DS2431_READ_SCRATCHPAD 0xAA |
| DS2431 Read Scratchpad command. | |
| #define | DS2431_COPY_SCRATCHPAD 0x55 |
| DS2431 Copy Scratchpad command. | |
| #define | DS2431_MATCH_ROM 0x55 |
| DS2431 Match ROM command (ROM-level addressing prefix). | |
| #define | DS2431_SKIP_ROM 0xCC |
| DS2431 Skip ROM command (ROM-level broadcast prefix). | |
| #define | DS2431_TPROG_US 11000 |
| Copy Scratchpad EEPROM programming hold-off in microseconds. | |
| #define | DS2431_READ_PASS 8 |
| Maximum EEPROM bytes read by one Read Memory bus transaction. | |
Functions | |
| void | ds2431_init (void) |
| Initialize DS2431 driver hardware and peripherals. | |
| void | ds2431_select (const uint8_t *rom) |
| Select which DS2431 device to address by its ROM address. | |
| void | ds2431_set_parasite (uint8_t parasite) |
| Declare the bus as parasite-powered. | |
| uint8_t | ds2431_parasite_mode (void) |
| Current parasite-power configuration of the driver. | |
| uint8_t | ds2431_last_command_ok (void) |
| Result of the last completed DS2431 operation. | |
| void | ds2431_read_memory (uint8_t *dst, uint16_t addr, uint8_t len) |
| Read up to DS2431_READ_PASS bytes of EEPROM (non-blocking). | |
| uint8_t | ds2431_read_memory_poll (void) |
| Advance the non-blocking Read Memory operation. | |
| uint8_t | ds2431_write_scratchpad (uint16_t addr, const uint8_t *data, uint8_t len) |
| Write up to 8 bytes into the scratchpad (non-blocking). | |
| uint8_t | ds2431_write_scratchpad_poll (void) |
| Advance the non-blocking Write Scratchpad operation. | |
| void | ds2431_read_scratchpad (uint8_t *buf) |
| Read the scratchpad frame (non-blocking). | |
| uint8_t | ds2431_read_scratchpad_poll (void) |
| Advance the non-blocking scratchpad frame read. | |
| void | ds2431_copy_scratchpad (void) |
| Copy the scratchpad into the EEPROM (non-blocking). | |
| uint8_t | ds2431_copy_scratchpad_poll (void) |
| Advance the non-blocking Copy Scratchpad operation. | |
Non-blocking DS2431 1 kbit EEPROM driver for STM32.
This driver implements a strictly non-blocking interface for the DS2431 EEPROM using hardware timers and DMA on STM32 microcontrollers, on top of the public 1-Wire layer primitives (onewire_reset() / onewire_write_slots() / onewire_read_data()). It is a self-contained second driver: it does not touch the DS18B20 driver or the 1-Wire layer internals, and is split into a core TU (src/ds2431.c, owns the context and the public start/poll API) and an engine TU (src/ds2431_txn.c, reset -> write -> read/wait on the caller-owned context via src/ds2431_internal.h).
Key features:
Device model (DS2431 datasheet): 128 bytes of EEPROM = 4 pages x 32 bytes, written through an 8-byte scratchpad in page-aligned 8-byte blocks. The scratchpad holds the block being written plus the latched target address and the end-offset status byte ES = (address + length - 1) & 0x07. The Read Scratchpad reply ends with an inverted CRC-16 over the command, the target address (TA1/TA2), the E/S byte and the 8 scratchpad data bytes; the driver reads and verifies it (onewire_crc16()) and additionally compares the TA1/TA2/ES echo against what the last Write Scratchpad latched. Because the device computes that CRC over what it actually stored, the read-back data bytes are also compared with the payload that was sent: a byte corrupted on the way to the device during Write Scratchpad passes the CRC and the echo, so only this comparison catches it before Copy Scratchpad commits it.
Usage: