ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
at24c08_nonlib.c File Reference
#include "fw_hal.h"

Go to the source code of this file.

Macros

#define AT24C_ADDR   0xA0
 

Functions

void Wait ()
 
void Start ()
 
void SendData (char dat)
 
void RecvACK ()
 
char RecvData ()
 
void SendACK ()
 
void SendNAK ()
 
void Stop ()
 
void I2C_Init (void)
 
void GPIO_Init (void)
 
int main (void)
 

Macro Definition Documentation

◆ AT24C_ADDR

#define AT24C_ADDR   0xA0

Definition at line 27 of file at24c08_nonlib.c.

Function Documentation

◆ GPIO_Init()

void GPIO_Init ( void  )

Definition at line 96 of file at24c08_nonlib.c.

97{
98 // SDA
100 // SCL
102}
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:89
@ GPIO_Pin_2
Definition: fw_gpio.h:47
@ GPIO_Pin_3
Definition: fw_gpio.h:48
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ GPIO_Mode_InOut_QBD
Definition: fw_gpio.h:23

◆ I2C_Init()

void I2C_Init ( void  )

I2C clock = FOSC / 2 / (prescaler * 2 + 4)

Definition at line 82 of file at24c08_nonlib.c.

83{
84 // Master mode
90 // Switch alternative port
92 // Start I2C
94}
#define I2C_SetClockPrescaler(__DIV__)
Definition: fw_i2c.h:71
@ I2C_WorkMode_Master
Definition: fw_i2c.h:24
#define I2C_SetWorkMode(__MODE__)
Definition: fw_i2c.h:65
#define I2C_SetEnabled(__STATE__)
Definition: fw_i2c.h:64
@ I2C_AlterPort_P32_P33
Definition: fw_i2c.h:51
#define I2C_SetPort(__ALTER_PORT__)
Definition: fw_i2c.h:121
@ HAL_State_ON
Definition: fw_types.h:71

◆ main()

int main ( void  )

Definition at line 104 of file at24c08_nonlib.c.

105{
106 uint8_t i, buf[20];
107
108 SYS_SetClock();
109 // UART1 configuration: baud 115200 with Timer2, 1T mode, no interrupt
111
112 GPIO_Init();
113 I2C_Init();
114
115 P_SW2 |= 0x80;
116
117 Start();
119 RecvACK();
120 SendData(0x00);
121 RecvACK();
122 SendData(0xAF);
123 RecvACK();
124 SendData(0xBF);
125 RecvACK();
126 SendData(0xCF);
127 RecvACK();
128 SendData(0xDF);
129 RecvACK();
130 SendData(0xEF);
131 RecvACK();
132 SendData(0xFF);
133 RecvACK();
134 Stop();
135 SYS_Delay(50);
136
137 while (1)
138 {
139 Start();
141 RecvACK();
142 SendData(0x00);
143 RecvACK();
144 Start();
145 SendData(AT24C_ADDR|0x01);
146 RecvACK();
147 buf[0] = RecvData();
148 SendACK();
149 buf[1] = RecvData();
150 SendNAK();
151 Stop();
152 UART1_TxHex(buf[0]);
153 UART1_TxChar(':');
154 UART1_TxHex(buf[1]);
155 UART1_TxChar(' ');
156
157 Start();
159 RecvACK();
160 SendData(0x01);
161 RecvACK();
162 Start();
163 SendData(AT24C_ADDR|0x01);
164 RecvACK();
165 buf[0] = RecvData();
166 SendACK();
167 buf[1] = RecvData();
168 SendNAK();
169 Stop();
170 UART1_TxHex(buf[0]);
171 UART1_TxChar(':');
172 UART1_TxHex(buf[1]);
173 UART1_TxChar(' ');
174
175 Start();
177 RecvACK();
178 SendData(0x02);
179 RecvACK();
180 Start();
181 SendData(AT24C_ADDR|0x01);
182 RecvACK();
183 buf[0] = RecvData();
184 SendACK();
185 buf[1] = RecvData();
186 SendNAK();
187 Stop();
188 UART1_TxHex(buf[0]);
189 UART1_TxChar(':');
190 UART1_TxHex(buf[1]);
191 UART1_TxChar(' ');
192
193 SYS_Delay(200);
194 }
195}
void Start()
void Stop()
void SendNAK()
void RecvACK()
void I2C_Init(void)
void GPIO_Init(void)
char RecvData()
void SendData(char dat)
#define AT24C_ADDR
void SendACK()
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
unsigned char uint8_t
Definition: fw_types.h:18
void UART1_TxChar(char dat)
Definition: fw_uart.c:72
@ UART1_BaudSource_Timer2
Definition: fw_uart.h:34
void UART1_TxHex(uint8_t hex)
Definition: fw_uart.c:79
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56
uint8_t __XDATA i

◆ RecvACK()

void RecvACK ( )

Definition at line 49 of file at24c08_nonlib.c.

50{
51 I2CMSCR = 0x03;
52 Wait();
53}
void Wait()
#define I2CMSCR

◆ RecvData()

char RecvData ( )

Definition at line 55 of file at24c08_nonlib.c.

56{
57 I2CMSCR = 0x04;
58 Wait();
59 return I2CRXD;
60}
#define I2CRXD

◆ SendACK()

void SendACK ( )

Definition at line 62 of file at24c08_nonlib.c.

63{
64 I2CMSST = 0x00;
65 I2CMSCR = 0x05;
66 Wait();
67}
#define I2CMSST

◆ SendData()

void SendData ( char  dat)

Definition at line 42 of file at24c08_nonlib.c.

43{
44 I2CTXD = dat;
45 I2CMSCR = 0x02;
46 Wait();
47}
__CODE int8_t dat[20]
#define I2CTXD

◆ SendNAK()

void SendNAK ( )

Definition at line 69 of file at24c08_nonlib.c.

70{
71 I2CMSST = 0x01;
72 I2CMSCR = 0x05;
73 Wait();
74}

◆ Start()

void Start ( )

Definition at line 36 of file at24c08_nonlib.c.

37{
38 I2CMSCR = 0x01;
39 Wait();
40}

◆ Stop()

void Stop ( )

Definition at line 76 of file at24c08_nonlib.c.

77{
78 I2CMSCR = 0x06;
79 Wait();
80}

◆ Wait()

void Wait ( )

Definition at line 30 of file at24c08_nonlib.c.

31{
32 while (!(I2CMSST & 0x40));
33 I2CMSST &= ~0x40;
34}