px-lib  0.9.2
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers
px_cat25m.h : On Semiconductor CAT25M SPI EEPROM Driver

Description

Driver that communicates with an On Semiconductor CAT25M EEPROM using SPI.

File(s):

Reference:

Macros

#define PX_CAT25M_EEPROM_SIZE_BYTES   (PX_CAT25M_PAGES*PX_CAT25M_PAGE_SIZE)
 EEPROM size (in bytes) More...
 
#define PX_CAT25M_ADR_MAX   (PX_CAT25M_EEPROM_SIZE_BYTES-1)
 Maximum adress. More...
 
#define PX_CAT25M_MAX_SPI_CLOCK_HZ   10000000
 Maximum SPI Clock rate. More...
 
#define PX_CAT25M_SPI_MODE   PX_SPI_MODE0
 SPI Clock / Data phase. More...
 
#define PX_CAT25M_SPI_DATA_ORDER   PX_SPI_DATA_ORDER_MSB
 SPI Data order. More...
 
#define PX_CAT25M_CFG_DEVICE   PX_CAT25M01
 Specify device. More...
 

Typedefs

typedef uint32_t px_cat25m_adr_t
 Address size. More...
 

Functions

void px_cat25m_init (px_spi_handle_t *handle)
 Initialise driver. More...
 
void px_cat25m_rd (void *buffer, px_cat25m_adr_t address, size_t nr_of_bytes)
 Read data from EEPROM. More...
 
void px_cat25m_rd_page (void *buffer, uint16_t page)
 Read a page from EEPROM. More...
 
void px_cat25m_rd_page_offset (void *buffer, uint16_t page, uint8_t start_byte_in_page, size_t nr_of_bytes)
 Partial read of data in a page of EEPROM. More...
 
void px_cat25m_wr_page (const void *buffer, uint16_t page)
 Write a page from EEPROM. More...
 
void px_cat25m_wr_page_offset (const void *buffer, uint16_t page, uint8_t start_byte_in_page, size_t nr_of_bytes)
 Partial write of data in a page of EEPROM. More...
 
bool px_cat25m_ready (void)
 Check if EEPROM is ready for the next read or write access. More...
 
uint8_t px_cat25m_status_rd (void)
 Read the status register of the EEPROM. More...
 
void px_cat25m_status_wr (uint8_t status)
 Write to the status register of the EEPROM. More...
 
void px_cat25m_wr_en (void)
 Enable writing. More...
 
void px_cat25m_wr_dis (void)
 Disable writing. More...
 

List CAT25M devices

#define PX_CAT25M01   0
 
#define PX_CAT25M02   1
 

Status register

#define PX_CAT25M_STATUS_WPEN   7
 Write Protect Enable. More...
 
#define PX_CAT25M_STATUS_IPL   6
 Identification Page Latch. More...
 
#define PX_CAT25M_STATUS_LIP   4
 Lock Identification Page. More...
 
#define PX_CAT25M_STATUS_BP1   3
 Block Protect bit 1. More...
 
#define PX_CAT25M_STATUS_BP0   2
 Block Protect bit 0. More...
 
#define PX_CAT25M_STATUS_WEL   1
 Write Enable Latch. More...
 
#define PX_CAT25M_STATUS_RDY   0
 Ready (inverted) More...
 

Macro Definition Documentation

◆ PX_CAT25M_EEPROM_SIZE_BYTES

#define PX_CAT25M_EEPROM_SIZE_BYTES   (PX_CAT25M_PAGES*PX_CAT25M_PAGE_SIZE)

EEPROM size (in bytes)

Definition at line 71 of file px_cat25m.h.

◆ PX_CAT25M_ADR_MAX

#define PX_CAT25M_ADR_MAX   (PX_CAT25M_EEPROM_SIZE_BYTES-1)

Maximum adress.

Definition at line 74 of file px_cat25m.h.

◆ PX_CAT25M_STATUS_WPEN

#define PX_CAT25M_STATUS_WPEN   7

Write Protect Enable.

Definition at line 78 of file px_cat25m.h.

◆ PX_CAT25M_STATUS_IPL

#define PX_CAT25M_STATUS_IPL   6

Identification Page Latch.

Definition at line 79 of file px_cat25m.h.

◆ PX_CAT25M_STATUS_LIP

#define PX_CAT25M_STATUS_LIP   4

Lock Identification Page.

Definition at line 80 of file px_cat25m.h.

◆ PX_CAT25M_STATUS_BP1

#define PX_CAT25M_STATUS_BP1   3

Block Protect bit 1.

Definition at line 81 of file px_cat25m.h.

◆ PX_CAT25M_STATUS_BP0

#define PX_CAT25M_STATUS_BP0   2

Block Protect bit 0.

Definition at line 82 of file px_cat25m.h.

◆ PX_CAT25M_STATUS_WEL

#define PX_CAT25M_STATUS_WEL   1

Write Enable Latch.

Definition at line 83 of file px_cat25m.h.

◆ PX_CAT25M_STATUS_RDY

#define PX_CAT25M_STATUS_RDY   0

Ready (inverted)

Definition at line 84 of file px_cat25m.h.

◆ PX_CAT25M_MAX_SPI_CLOCK_HZ

#define PX_CAT25M_MAX_SPI_CLOCK_HZ   10000000

Maximum SPI Clock rate.

Definition at line 88 of file px_cat25m.h.

◆ PX_CAT25M_SPI_MODE

#define PX_CAT25M_SPI_MODE   PX_SPI_MODE0

SPI Clock / Data phase.

Definition at line 90 of file px_cat25m.h.

◆ PX_CAT25M_SPI_DATA_ORDER

#define PX_CAT25M_SPI_DATA_ORDER   PX_SPI_DATA_ORDER_MSB

SPI Data order.

Definition at line 92 of file px_cat25m.h.

◆ PX_CAT25M_CFG_DEVICE

#define PX_CAT25M_CFG_DEVICE   PX_CAT25M01

Specify device.

Definition at line 33 of file px_cat25m_cfg_template.h.

Typedef Documentation

◆ px_cat25m_adr_t

typedef uint32_t px_cat25m_adr_t

Address size.

Definition at line 96 of file px_cat25m.h.

Function Documentation

◆ px_cat25m_init()

void px_cat25m_init ( px_spi_handle_t handle)

Initialise driver.

Parameters
handleSPI handle to use for SPI slave device

Definition at line 48 of file px_cat25m.c.

◆ px_cat25m_rd()

void px_cat25m_rd ( void *  buffer,
px_cat25m_adr_t  address,
size_t  nr_of_bytes 
)

Read data from EEPROM.

This function reads data from EEPROM and stores it in the specified buffer.

Parameters
[out]bufferBuffer to store read data
[in]address0 to PX_CAT25M_ADR_MAX
[in]nr_of_bytesNumber of bytes to read

Definition at line 56 of file px_cat25m.c.

◆ px_cat25m_rd_page()

void px_cat25m_rd_page ( void *  buffer,
uint16_t  page 
)

Read a page from EEPROM.

This function reads a page of data from EEPROM and stores it in the specified buffer. The buffer must be at least PX_CAT25M_PAGE_SIZE bytes in size to accomodate a full page.

The EEPROM has PX_CAT25M_PAGES pages.

Parameters
[out]bufferBuffer to store read data
[in]page0 to (PX_CAT25M_PAGES-1)

Definition at line 86 of file px_cat25m.c.

◆ px_cat25m_rd_page_offset()

void px_cat25m_rd_page_offset ( void *  buffer,
uint16_t  page,
uint8_t  start_byte_in_page,
size_t  nr_of_bytes 
)

Partial read of data in a page of EEPROM.

This function reads part of a page of data from EEPROM and stores it in the specified buffer. The buffer must be at least nr_of_bytes in size to the read data.

Note

Only read up to the end of the specified page. If the page boundary is exceeded, the index will wrap to the start of the page, i.e. only the content of the specified page will be read.

Parameters
[out]bufferBuffer to store read data
[in]page0 to (PX_CAT25M_PAGES-1)
[in]start_byte_in_pageIndex of first byte to read (0 to PX_CAT25M_PAGE_SIZE - 1)
[in]nr_of_bytesNumber of bytes to read

Definition at line 109 of file px_cat25m.c.

◆ px_cat25m_wr_page()

void px_cat25m_wr_page ( const void *  buffer,
uint16_t  page 
)

Write a page from EEPROM.

This function writes a page of data to EEPROM using the specified buffer as the source. The buffer must contain at least PX_CAT25M_PAGE_SIZE bytes of data.

The EEPROM has PX_CAT25M_PAGES pages.

Parameters
[in]bufferBuffer containing data to be written
[in]page0 to (PX_CAT25M_PAGES-1)

Definition at line 134 of file px_cat25m.c.

◆ px_cat25m_wr_page_offset()

void px_cat25m_wr_page_offset ( const void *  buffer,
uint16_t  page,
uint8_t  start_byte_in_page,
size_t  nr_of_bytes 
)

Partial write of data in a page of EEPROM.

This function writes a part of a page of data to EEPROM using the specified buffer as source. The buffer must contain at least nr_of_bytes of data.

Note

Only write up to the end of the specified page. If the page boundary is exceeded, the index will wrap to the start of the page, i.e. only the content of the specified page will be written.

Parameters
[in]bufferBuffer containing data to be written
[in]page0 to (PX_CAT25M_PAGES-1)
[in]start_byte_in_pageIndex of first byte to write (0 to PX_CAT25M_PAGE_SIZE - 1)
[in]nr_of_bytesNumber of bytes to write

Definition at line 163 of file px_cat25m.c.

◆ px_cat25m_ready()

bool px_cat25m_ready ( void  )

Check if EEPROM is ready for the next read or write access.

When data is written to EEPROM, the microcontroller must wait until the operation is finished, before the next one is attempted. This function allows the microcontroller to do something else while waiting for the operation to finish.

Return values
trueEEPROM is ready for next read or write access.
falseEEPROM is busy writing.

Definition at line 194 of file px_cat25m.c.

◆ px_cat25m_status_rd()

uint8_t px_cat25m_status_rd ( void  )

Read the status register of the EEPROM.

The status register contains flags (e.g. PX_CAT25M_STATUS_RDY). This function can be used to check that a valid and working EEPROM device is connected.

Returns
uint8_t Status register value

Definition at line 206 of file px_cat25m.c.

◆ px_cat25m_status_wr()

void px_cat25m_status_wr ( uint8_t  status)

Write to the status register of the EEPROM.

Parameters
statusValue to write to the status register

Definition at line 220 of file px_cat25m.c.

◆ px_cat25m_wr_en()

void px_cat25m_wr_en ( void  )

Enable writing.

Definition at line 230 of file px_cat25m.c.

◆ px_cat25m_wr_dis()

void px_cat25m_wr_dis ( void  )

Disable writing.

Definition at line 239 of file px_cat25m.c.