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

Go to the source code of this file.

Macros

#define BUF_SIZE   256
 

Functions

 INTERRUPT (I2C_Routine, EXTI_VectI2C)
 
void main ()
 

Variables

__BIT waitDeviceAddress
 
__BIT waitMemoryAddress
 
__XDATA uint8_t buffer [BUF_SIZE]
 
__XDATA uint8_t addr
 

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   256

Definition at line 3 of file i2c_slave.c.

Function Documentation

◆ INTERRUPT()

INTERRUPT ( I2C_Routine  ,
EXTI_VectI2C   
)

Definition at line 9 of file i2c_slave.c.

10{
11 SFRX_ON();
12
14 {
16 }
17 else if (I2C_IsSlaveRecvInterrupt())
18 {
20 if (waitDeviceAddress) // Received device address
21 {
23 }
24 else if (waitMemoryAddress) // Received memory address
25 {
27 addr = I2CRXD;
29 }
30 else // Received data
31 {
32 buffer[addr++] = I2CRXD;
33 addr = addr % BUF_SIZE;
34 }
35 }
36 else if (I2C_IsSlaveSendInterrupt())
37 {
39 if (I2C_ReadSlaveAckIn()) // Stop when received NAK
40 {
41 I2CTXD = 0xFF;
42 }
43 else // Continue sending
44 {
45 I2CTXD = buffer[addr++];
46 addr = addr % BUF_SIZE;
47 }
48 }
49 else if (I2C_IsSlaveStopInterrupt())
50 {
54 }
55 SFRX_OFF();
56}
#define I2C_ClearSlaveSendInterrupt()
Definition: fw_i2c.h:110
#define I2C_IsSlaveStopInterrupt()
Definition: fw_i2c.h:111
#define I2C_IsSlaveSendInterrupt()
Definition: fw_i2c.h:109
#define I2C_IsSlaveStartInterrupt()
Definition: fw_i2c.h:105
#define I2C_ClearSlaveRecvInterrupt()
Definition: fw_i2c.h:108
#define I2C_ClearSlaveStartInterrupt()
Definition: fw_i2c.h:106
#define I2C_ClearSlaveStopInterrupt()
Definition: fw_i2c.h:112
#define I2C_ReadSlaveAckIn()
Definition: fw_i2c.h:113
#define I2C_IsSlaveRecvInterrupt()
Definition: fw_i2c.h:107
#define I2CRXD
#define I2CTXD
#define SFRX_ON()
Definition: fw_types.h:112
#define SFRX_OFF()
Definition: fw_types.h:113
__XDATA uint8_t buffer[BUF_SIZE]
Definition: i2c_slave.c:7
__XDATA uint8_t addr
Definition: i2c_slave.c:7
#define BUF_SIZE
Definition: i2c_slave.c:3
__BIT waitMemoryAddress
Definition: i2c_slave.c:6
__BIT waitDeviceAddress
Definition: i2c_slave.c:5

◆ main()

void main ( void  )

Definition at line 58 of file i2c_slave.c.

59{
61 // P15:SCL, P14:SDA
63
64 I2CSLADR = 0x5A;
65
72
75 addr = 0;
77
79
80 while (1);
81}
#define EXTI_Global_SetIntState(__STATE__)
Definition: fw_exti.h:115
#define EXTI_I2C_SetSlvRecvIntState(__STATE__)
Definition: fw_exti.h:147
#define EXTI_I2C_SetSlvSendIntState(__STATE__)
Definition: fw_exti.h:148
#define EXTI_I2C_SetSlvStopIntState(__STATE__)
Definition: fw_exti.h:149
#define EXTI_I2C_SetSlvStartIntState(__STATE__)
Definition: fw_exti.h:146
#define I2C_ClearAllSlaveInterrupts()
Definition: fw_i2c.h:115
@ I2C_WorkMode_Slave
Definition: fw_i2c.h:23
#define I2C_SetWorkMode(__MODE__)
Definition: fw_i2c.h:65
#define I2C_SetEnabled(__STATE__)
Definition: fw_i2c.h:64
@ I2C_AlterPort_P15_P14
Definition: fw_i2c.h:48
#define I2C_SetPort(__ALTER_PORT__)
Definition: fw_i2c.h:121
#define I2CSLADR
@ HAL_State_ON
Definition: fw_types.h:71

Variable Documentation

◆ addr

__XDATA uint8_t addr

Definition at line 7 of file i2c_slave.c.

◆ buffer

__XDATA uint8_t buffer[BUF_SIZE]

Definition at line 7 of file i2c_slave.c.

◆ waitDeviceAddress

__BIT waitDeviceAddress

Definition at line 5 of file i2c_slave.c.

◆ waitMemoryAddress

__BIT waitMemoryAddress

Definition at line 6 of file i2c_slave.c.