小弟剛剛使用CY21434,作為主設備,虛心向前輩們請教,怎麼樣正確的進行I2C讀寫? 工程如附件我代碼如下:
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
//#include <I2CHWCommon.h>
//#include <I2CHWmstr.h>
#define SLAVE_ADDRESS 0x77
//#define I2CHW_CompleteXfer 0x00
//#define I2CHW_RD_COMPLETE 0x04
void TXandRX();
void IIC_TX();
void IIC_RX();
BYTE txBuffer[8];
BYTE rxBuffer[8];
void main()
{
// Insert your main routine code here.
LCD_Start();
I2CHW_Start();
I2CHW_EnableMstr();
M8C_EnableGInt;
I2CHW_EnableInt();
while(1){
I2CHW_fReadBytes(SLAVE_ADDRESS, rxBuffer, 8, I2CHW_CompleteXfer);
while(!I2CHW_bReadI2CStatus() & I2CHW_RD_COMPLETE);
I2CHW_ClrRdStatus();
LCD_Position(0,0);
LCD_PrCString(" ");
LCD_Position(0,0);
LCD_PrHexByte(rxBuffer[0]&0xff);
LCD_Position(0,2);
LCD_PrCString(" ");
LCD_Position(0,2);
LCD_PrHexByte(rxBuffer[1]&0xff);
LCD_Position(0,4);
LCD_PrCString(" ");
LCD_Position(0,4);
LCD_PrHexByte(rxBuffer[2]&0xff);
LCD_Position(0,6);
LCD_PrCString(" ");
LCD_Position(0,6);
LCD_PrHexByte(rxBuffer[3]&0xff);
LCD_Position(0,8);
LCD_PrCString(" ");
LCD_Position(0,8);
LCD_PrHexByte(rxBuffer[4]&0xff);
LCD_Position(0,10);
LCD_PrCString(" ");
LCD_Position(0,10);
LCD_PrHexByte(rxBuffer[5]&0xff);
LCD_Position(0,12);
LCD_PrCString(" ");
LCD_Position(0,12);
LCD_PrHexByte(rxBuffer[6]&0xff);
LCD_Position(0,14);
LCD_PrCString(" ");
LCD_Position(0,14);
LCD_PrHexByte(rxBuffer[7]&0xff);
}
} |