Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIT 24 I2C Test 로봇 SW 교육원 조용수.

Similar presentations


Presentation on theme: "UNIT 24 I2C Test 로봇 SW 교육원 조용수."— Presentation transcript:

1 UNIT 24 I2C Test 로봇 SW 교육원 조용수

2 학습 목표 I2C Master/Slave Test 24LC64 EEPROM Test
\M051_Series_BSP_CMSIS_Rev \SampleCode\RegBased\I2C_Master .\M051_Series_BSP_CMSIS_Rev \SampleCode\RegBased\I2C_Slave 24LC64 EEPROM Test - \M051_Series_BSP_CMSIS_Rev \SampleCode\ RegBased\I2C_EEPROM

3 I2C Sample Test I2C Port 연결

4 I2C Sample Test 2 개의 보드를 연결하여 Master / Slave 의 소스를 각각 Downloading 하여 테스트 한다.

5 I2C Source Init 수정 void SYS_Init(void) {
/* Enable UART module clock */ CLK->APBCLK |= CLK_APBCLK_UART0_EN_Msk | CLK_APBCLK_I2C0_EN_Msk; /* Update System Core Clock */ /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock and cyclesPerUs automatically. */ SystemCoreClockUpdate(); /* Set P3 multi-function pins for UART0 RXD and TXD, and set P3.4 and P3.5 for I2C0 SDA and SCL */ SYS->P3_MFP = SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0 | SYS_MFP_P34_SDA0 | SYS_MFP_P35_SCL0; } void UART0_Init(void) UART_Open(UART0, ); This is the read operation of EEPROM. The first four steps are the same with the Write operation.

6 I2C Status

7 I2C Write Status This is the write operation of EEPROM.
The flow is similar to the last example for usage of I2C control register. In data transfer, it includes two bytes address and one byte data. We will use I2C driver to implement this operation. We follow the write operation to send start, slave address, address high byte, address low byte, data, and stop in sequence.

8 I2C Write Sample Source void I2C_MasterTx(uint32_t u32Status) {
if(u32Status == 0x08) /* START has been transmitted */ I2C0->I2CDAT = g_u8DeviceAddr << 1; /* Write SLA+W to Register I2CDAT */ I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI); } else if(u32Status == 0x18) /* SLA+W has been transmitted and ACK has been received */ I2C0->I2CDAT = g_au8TxData[g_u8DataLen++]; else if(u32Status == 0x20) /* SLA+W has been transmitted and NACK has been received */ I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_STA_STO_SI); else if(u32Status == 0x28) /* DATA has been transmitted and ACK has been received */ if(g_u8DataLen != 3) { } else { I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_STO_SI); g_u8EndFlag = 1; printf("Status 0x%x is NOT processed\n", u32Status); This is the write operation of EEPROM. The flow is similar to the last example for usage of I2C control register. In data transfer, it includes two bytes address and one byte data. We will use I2C driver to implement this operation. We follow the write operation to send start, slave address, address high byte, address low byte, data, and stop in sequence.

9 I2C Read Status This is the read operation of EEPROM.
The first four steps are the same with the Write operation.

10 I2C Read Source void I2C_MasterRx(uint32_t u32Status) {
if(u32Status == 0x08) /* START has been transmitted and prepare SLA+W */ I2C0->I2CDAT = g_u8DeviceAddr << 1; /* Write SLA+W to Register I2CDAT */ I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI); } else if(u32Status == 0x18) /* SLA+W has been transmitted and ACK has been received */ I2C0->I2CDAT = g_au8TxData[g_u8DataLen++]; else if(u32Status == 0x20) /* SLA+W has been transmitted and NACK has been received */ I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_STA_STO_SI); else if(u32Status == 0x28) /* DATA has been transmitted and ACK has been received */ if(g_u8DataLen != 2) else I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_STA_SI); This is the read operation of EEPROM. The first four steps are the same with the Write operation.

11 I2C Read Source else if(u32Status == 0x10) /* Repeat START has been transmitted and prepare SLA+R */ { I2C0->I2CDAT = ((g_u8DeviceAddr << 1) | 0x01); /* Write SLA+R to Register I2CDAT */ I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI); } else if(u32Status == 0x40) /* SLA+R has been transmitted and ACK has been received */ else if(u32Status == 0x58) /* DATA has been received and NACK has been returned */ g_u8RxData = I2C0->I2CDAT; I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_STO_SI); g_u8EndFlag = 1; else /* TO DO */ printf("Status 0x%x is NOT processed\n", u32Status); This is the read operation of EEPROM. The first four steps are the same with the Write operation.

12 I2C 24LC64 Test 24LC64 는 8K x 8 bit 를 저장 가능한 메모리로,
I2C 기능을 이용하여 Read/Write 동작을 수행한다.


Download ppt "UNIT 24 I2C Test 로봇 SW 교육원 조용수."

Similar presentations


Ads by Google