eeprom9 2.1.0.0
eeprom9.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef EEPROM9_H
29#define EEPROM9_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define EEPROM9_HOLD_DISABLE 0x00
75#define EEPROM9_HOLD_ENABLE 0x01
76#define EEPROM9_WRITE_PROTECT_DISABLE 0x00
77#define EEPROM9_WRITE_PROTECT_ENABLE 0x01
78#define EEPROM9_WRITE_ENABLE 0x00
79#define EEPROM9_WRITE_DISABLE 0x01
80
85#define EEPROM9_SRWD_MASK 0x80
86#define EEPROM9_TB_MASK 0x40
87#define EEPROM9_BP2_MASK 0x10
88#define EEPROM9_BP1_MASK 0x08
89#define EEPROM9_BP0_MASK 0x04
90#define EEPROM9_WEL_MASK 0x02
91#define EEPROM9_WIP_MASK 0x01
92
97#define EEPROM9_ST_MANUFACTURER_CODE 0x20
98
103#define EEPROM9_MEMORY_ADDR_START 0x00000000ul
104#define EEPROM9_MEMORY_ADDR_END 0x003FFFFFul
105
110#define EEPROM9_CMD_WREN 0x06
111#define EEPROM9_CMD_WRDI 0x04
112#define EEPROM9_CMD_RDSR 0x05
113#define EEPROM9_CMD_WRSR 0x01
114#define EEPROM9_CMD_READ 0x03
115#define EEPROM9_CMD_FREAD 0x0B
116#define EEPROM9_CMD_FDREAD 0x3B
117#define EEPROM9_CMD_FQREAD 0x6B
118#define EEPROM9_CMD_PGWR 0x02
119#define EEPROM9_CMD_PGPR 0x0A
120#define EEPROM9_CMD_PGER 0xDB
121#define EEPROM9_CMD_SCER 0x20
122#define EEPROM9_CMD_BKER 0xD8
123#define EEPROM9_CMD_CHER 0xC7
124#define EEPROM9_CMD_RDID 0x83
125#define EEPROM9_CMD_FRDID 0x8B
126#define EEPROM9_CMD_WRID 0x82
127#define EEPROM9_CMD_DPD 0xB9
128#define EEPROM9_CMD_RDPD 0xAB
129#define EEPROM9_CMD_JEDPC 0x9F
130#define EEPROM9_CMD_RDCR 0x15
131#define EEPROM9_CMD_RDVR 0x85
132#define EEPROM9_CMD_WRVR 0x81
133#define EEPROM9_CMD_CLRSF 0x50
134#define EEPROM9_CMD_RDSFDP 0x5A
135#define EEPROM9_CMD_RSTEN 0x66
136#define EEPROM9_CMD_RESET 0x99
137
146#define EEPROM9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
147#define EEPROM9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
148
149 // eeprom9_set
150
165#define EEPROM9_MAP_MIKROBUS( cfg, mikrobus ) \
166 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
167 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
168 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
169 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
170 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
171 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_INT )
172
173 // eeprom9_map
174 // eeprom9
175
180typedef struct
181{
182 // Output pins
183 digital_out_t wp;
184 digital_out_t hld;
186 // Modules
187 spi_master_t spi;
189 pin_name_t chip_select;
191} eeprom9_t;
192
197typedef struct
198{
199 // Communication gpio pins
200 pin_name_t miso;
201 pin_name_t mosi;
202 pin_name_t sck;
203 pin_name_t cs;
205 // Additional gpio pins
206 pin_name_t wp;
207 pin_name_t hld;
209 // static variable
210 uint32_t spi_speed;
211 spi_master_mode_t spi_mode;
212 spi_master_chip_select_polarity_t cs_polarity;
215
220typedef struct
221{
223 uint8_t spi_code;
225} id_data_t;
226
231typedef enum
232{
234 EEPROM9_ERROR = -1
235
237
254
269
284err_t eeprom9_generic_write ( eeprom9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
285
300err_t eeprom9_generic_read ( eeprom9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
301
311void eeprom9_set_hold ( eeprom9_t *ctx, uint8_t en_hold );
312
322void eeprom9_set_write_protection ( eeprom9_t *ctx, uint8_t en_wp );
323
335err_t eeprom9_send_cmd ( eeprom9_t *ctx, uint8_t cmd );
336
349err_t eeprom9_set_write_enable ( eeprom9_t *ctx, uint8_t en_write );
350
365err_t eeprom9_read_memory ( eeprom9_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint8_t len );
366
381err_t eeprom9_write_memory ( eeprom9_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint8_t len );
382
394err_t eeprom5_get_status_reg ( eeprom9_t *ctx, uint8_t *status_data );
395
407
419err_t eeprom9_block_erase ( eeprom9_t *ctx, uint32_t block_addr );
420
432err_t eeprom9_sector_erase ( eeprom9_t *ctx, uint32_t sector_addr );
433
445err_t eeprom9_page_erase ( eeprom9_t *ctx, uint32_t page_addr );
446
459
460#ifdef __cplusplus
461}
462#endif
463#endif // EEPROM9_H
464
465 // eeprom9
466
467// ------------------------------------------------------------------------ END
eeprom9_return_value_t
EEPROM 9 Click return value data.
Definition eeprom9.h:232
@ EEPROM9_OK
Definition eeprom9.h:233
@ EEPROM9_ERROR
Definition eeprom9.h:234
err_t eeprom9_write_memory(eeprom9_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint8_t len)
EEPROM 9 memory writing function.
void eeprom9_set_hold(eeprom9_t *ctx, uint8_t en_hold)
EEPROM 9 set hold pin state function.
err_t eeprom5_get_status_reg(eeprom9_t *ctx, uint8_t *status_data)
EEPROM 9 read status function.
err_t eeprom9_generic_read(eeprom9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
EEPROM 9 data reading function.
err_t eeprom9_chip_erase(eeprom9_t *ctx)
EEPROM 9 chip memory erase function.
void eeprom9_set_write_protection(eeprom9_t *ctx, uint8_t en_wp)
EEPROM 9 set write protection state function.
err_t eeprom9_generic_write(eeprom9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
EEPROM 9 data writing function.
err_t eeprom9_init(eeprom9_t *ctx, eeprom9_cfg_t *cfg)
EEPROM 9 initialization function.
void eeprom9_cfg_setup(eeprom9_cfg_t *cfg)
EEPROM 9 configuration object setup function.
err_t eeprom9_block_erase(eeprom9_t *ctx, uint32_t block_addr)
EEPROM 9 memory block erase function.
err_t eeprom9_sector_erase(eeprom9_t *ctx, uint32_t sector_addr)
EEPROM 9 memory sector erase function.
err_t eeprom9_read_identification(eeprom9_t *ctx, id_data_t *id_data)
EEPROM 9 read identification function.
err_t eeprom9_read_memory(eeprom9_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint8_t len)
EEPROM 9 memory reading function.
err_t eeprom9_set_write_enable(eeprom9_t *ctx, uint8_t en_write)
EEPROM 9 enable write function.
err_t eeprom9_page_erase(eeprom9_t *ctx, uint32_t page_addr)
EEPROM 9 memory page erase function.
err_t eeprom9_send_cmd(eeprom9_t *ctx, uint8_t cmd)
EEPROM 9 send command function.
This file contains SPI specific macros, functions, etc.
EEPROM 9 Click configuration object.
Definition eeprom9.h:198
pin_name_t hld
Definition eeprom9.h:207
spi_master_chip_select_polarity_t cs_polarity
Definition eeprom9.h:212
pin_name_t sck
Definition eeprom9.h:202
spi_master_mode_t spi_mode
Definition eeprom9.h:211
pin_name_t mosi
Definition eeprom9.h:201
uint32_t spi_speed
Definition eeprom9.h:210
pin_name_t wp
Definition eeprom9.h:206
pin_name_t miso
Definition eeprom9.h:200
pin_name_t cs
Definition eeprom9.h:203
EEPROM 9 Click context object.
Definition eeprom9.h:181
digital_out_t hld
Definition eeprom9.h:184
spi_master_t spi
Definition eeprom9.h:187
pin_name_t chip_select
Definition eeprom9.h:189
digital_out_t wp
Definition eeprom9.h:183
EEPROM 9 Click identification data.
Definition eeprom9.h:221
uint8_t spi_code
Definition eeprom9.h:223
uint8_t memory_density
Definition eeprom9.h:224
uint8_t manufact_code
Definition eeprom9.h:222