LibDriver FM24CLXX
Loading...
Searching...
No Matches
driver_fm24clxx_read_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static fm24clxx_handle_t gs_handle;
41
52{
53 uint8_t res, i, j;
54 uint8_t buf[12];
55 uint8_t buf_check[12];
56 uint16_t inc;
57 fm24clxx_info_t info;
58
59 /* link interface function */
69
70 /* get information */
71 res = fm24clxx_info(&info);
72 if (res != 0)
73 {
74 fm24clxx_interface_debug_print("fm24clxx: get info failed.\n");
75
76 return 1;
77 }
78 else
79 {
80 /* print chip information */
81 fm24clxx_interface_debug_print("fm24clxx: chip is %s.\n", info.chip_name);
82 fm24clxx_interface_debug_print("fm24clxx: manufacturer is %s.\n", info.manufacturer_name);
83 fm24clxx_interface_debug_print("fm24clxx: interface is %s.\n", info.interface);
84 fm24clxx_interface_debug_print("fm24clxx: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
85 fm24clxx_interface_debug_print("fm24clxx: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
86 fm24clxx_interface_debug_print("fm24clxx: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
87 fm24clxx_interface_debug_print("fm24clxx: max current is %0.2fmA.\n", info.max_current_ma);
88 fm24clxx_interface_debug_print("fm24clxx: max temperature is %0.1fC.\n", info.temperature_max);
89 fm24clxx_interface_debug_print("fm24clxx: min temperature is %0.1fC.\n", info.temperature_min);
90 }
91
92 /* set chip type */
93 res = fm24clxx_set_type(&gs_handle, type);
94 if (res != 0)
95 {
96 fm24clxx_interface_debug_print("fm24clxx: set type failed.\n");
97
98 return 1;
99 }
100
101 /* set iic addr pin */
102 res = fm24clxx_set_addr_pin(&gs_handle, address);
103 if (res != 0)
104 {
105 fm24clxx_interface_debug_print("fm24clxx: set address pin failed.\n");
106
107 return 1;
108 }
109
110 /* fm24clxx init */
111 res = fm24clxx_init(&gs_handle);
112 if (res != 0)
113 {
114 fm24clxx_interface_debug_print("fm24clxx: init failed.\n");
115
116 return 1;
117 }
118
119 /* start read test */
120 fm24clxx_interface_debug_print("fm24clxx: start read test.\n");
121 inc = ((uint16_t)type + 1) / 8;
122 for (i = 0; i < 8; i++)
123 {
124 for (j = 0; j < 12; j++)
125 {
126 buf[j] = (uint8_t)(rand() % 256);
127 }
128
129 /* write data */
130 res = fm24clxx_write(&gs_handle, i*inc, (uint8_t *)buf, 12);
131 if (res != 0)
132 {
133 fm24clxx_interface_debug_print("fm24clxx: write failed.\n");
134 (void)fm24clxx_deinit(&gs_handle);
135
136 return 1;
137 }
138
139 /* read data */
140 res = fm24clxx_read(&gs_handle, i*inc, (uint8_t *)buf_check, 12);
141 if (res != 0)
142 {
143 fm24clxx_interface_debug_print("fm24clxx: read failed.\n");
144 (void)fm24clxx_deinit(&gs_handle);
145
146 return 1;
147 }
148 for (j = 0; j < 12; j++)
149 {
150 /* check data */
151 if (buf[j] != buf_check[j])
152 {
153 fm24clxx_interface_debug_print("fm24clxx: check error.\n");
154 (void)fm24clxx_deinit(&gs_handle);
155
156 return 1;
157 }
158 }
159 fm24clxx_interface_debug_print("fm24clxx: 0x%04X read write test passed.\n", i*inc);
160 }
161
162 /* finish read test */
163 fm24clxx_interface_debug_print("fm24clxx: finish read test.\n");
164 (void)fm24clxx_deinit(&gs_handle);
165
166 return 0;
167}
driver fm24clxx read test header file
uint8_t fm24clxx_set_addr_pin(fm24clxx_handle_t *handle, fm24clxx_address_t addr_pin)
set the chip address pin
uint8_t fm24clxx_init(fm24clxx_handle_t *handle)
initialize the chip
struct fm24clxx_handle_s fm24clxx_handle_t
fm24clxx handle structure definition
uint8_t fm24clxx_read(fm24clxx_handle_t *handle, uint16_t address, uint8_t *buf, uint16_t len)
read bytes from the chip
fm24clxx_address_t
fm24clxx address enumeration definition
fm24clxx_t
fm24clxx type enumeration definition
struct fm24clxx_info_s fm24clxx_info_t
fm24clxx information structure definition
uint8_t fm24clxx_set_type(fm24clxx_handle_t *handle, fm24clxx_t type)
set the chip type
uint8_t fm24clxx_write(fm24clxx_handle_t *handle, uint16_t address, uint8_t *buf, uint16_t len)
write bytes to the chip
uint8_t fm24clxx_info(fm24clxx_info_t *info)
get chip's information
uint8_t fm24clxx_deinit(fm24clxx_handle_t *handle)
close the chip
uint8_t fm24clxx_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void fm24clxx_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t fm24clxx_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t fm24clxx_interface_iic_write_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus write with 16 bits register address
uint8_t fm24clxx_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with 16 bits register address
void fm24clxx_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t fm24clxx_interface_iic_init(void)
interface iic bus init
uint8_t fm24clxx_interface_iic_deinit(void)
interface iic bus deinit
uint8_t fm24clxx_read_test(fm24clxx_t type, fm24clxx_address_t address)
read test
char manufacturer_name[32]