#include #include "yc11xx.h" #include "ycdef.h" #include "yc11xx_uart.h" #include "yc11xx_gpio.h" #include "iic.h" #include "systick.h" void LED_Run(void) { static uint32_t times = 0; times++; if(times>0x50000) { times = 0; GPIO_CONFIG(2) = (GPIO_CONFIG(2)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH; } } #define IIC_SCL_GPIO_NUM 25 #define IIC_SDA_GPIO_NUM 6 #define I2CBUFSIZE 256 void debug_print(uint32_t data) { USART_SendData(UARTB,(data>>24) & 0xff); USART_SendData(UARTB,(data>>16) & 0xff); USART_SendData(UARTB,(data>>8 ) & 0xff); USART_SendData(UARTB,(data>>0 ) & 0xff); } /** *@brief IIC(AT24C02)Write the specified amount of data at the specified location *@param Device address *@param addr *@param len *@param data *@return None */ //void AT24C02_WriteData(uint8_t devaddr,uint8_t addr,uint8_t Len,uint8_t *p) //{ // uint8_t Page_remain = 8 - addr%8; // if(Page_remain >= Len) // { // Page_remain = Len; // } // while(1) // { // I2C_SendDataFromBuff(devaddr,addr,p,Len); // if(Page_remain == Len) break; // addr+=Page_remain; // p+=Page_remain; // Len-=Page_remain; // if(Len>=8) Page_remain =8; // else Page_remain=Len; // } //} ///** // *@brief IIC(AT24C02)read and write test // *@param None. // *@return normal return 1 ,fild return 0 // */ //void I2c_Test() //{ //#define SEND_BUFF_SIZE 4 //#define RECV_BUFF_SIZE 4 //#define DEV_ADDR_EEPROM 0x50 //#define REG_ADDR_EEPROM 0x02 //#define I2C_Txlen_SIZE 4 //#define I2C_Rxlen_SIZE 4 // // I2C_InitTypeDef mem_test; // mem_test.I2C_RXLen = 64; // mem_test.I2C_TXLen = 64; // mem_test.I2C_ClockSpeed = IICD_CLOCKSPEED400KHZ ; // I2C_Init(&mem_test); // printf ("iic init \n"); // GPIO_SetGpioMultFunction(IIC_SCL_GPIO_NUM, GPCFG_IIC_SCL); //set gpio function to iic scl // GPIO_SetGpioMultFunction(IIC_SDA_GPIO_NUM, GPCFG_IIC_SDA ); //setbuf gpio function to iic sda // GPIO_SetGpioMultFunction(29,0); // GPIO_SetGpioMultFunction(30,0); // uint8_t Data = 0; // uint8_t send_buff[SEND_BUFF_SIZE]={Data++, Data++, Data++, Data++}; // uint8_t recv_buff[RECV_BUFF_SIZE]; // uint32_t DevAddr = DEV_ADDR_EEPROM; // uint32_t RegAddr = REG_ADDR_EEPROM; // uint16_t TxLen = I2C_Txlen_SIZE; // uint8_t* TxBuff = send_buff; // uint16_t RxLen = I2C_Rxlen_SIZE; // uint8_t* RxBuff = recv_buff; // printf ("init data\n"); // while(1){ // // uint32_t i,RxData=0; //#if 0 // I2C_SendData(DevAddr, I2C_REGADDR16BITS(RegAddr), Data); // printf("Data = 0x%02x\n",Data); // Data ++; // delay_ms(500); // // RxData = I2C_ReceiveData( DevAddr, I2C_REGADDR16BITS(RegAddr)); // printf("RxData = 0x%02x\n",RxData); // delay_ms(500); // // I2C_SendDataFromBuff(DevAddr, I2C_REGADDR16BITS(RegAddr), TxBuff, TxLen); // // for(i=0;i<4;i++)printf("TxBuff[%d] = 0x%02x ,",i,TxBuff[i]); // printf("\n"); // delay_ms(500); // // I2C_ReadDatatoBuff( DevAddr, I2C_REGADDR16BITS(RegAddr), RxBuff, RxLen); // for(i=0;i<4;i++)printf("RxBuff[%d] = 0x%02x ,",i,RxBuff[i]); // printf("\n"); // delay_ms(500); //#else // I2C_SendData(DevAddr, I2C_REGADDR8BITS(RegAddr), Data); // printf("Data = 0x%02x\n",Data); // Data ++; // delay_ms(1); // // RxData=I2C_ReceiveData( DevAddr, I2C_REGADDR8BITS(RegAddr)); // printf("RxData = 0x%02x\n",RxData); // delay_ms(50); // // I2C_SendDataFromBuff(DevAddr, I2C_REGADDR8BITS(RegAddr), TxBuff, TxLen); // for(i=0;i<4;i++)printf("TxBuff[%d] = 0x%02x ,",i,TxBuff[i]); // printf("\n"); // delay_ms(500); // // I2C_ReadDatatoBuff( DevAddr, I2C_REGADDR8BITS(RegAddr), RxBuff, RxLen); // for(i=0;i<4;i++)printf("RxBuff[%d] = 0x%02x ,",i,RxBuff[i]); // printf("\n"); // delay_ms(500); //#endif // } // printf("welcome\n"); //} int main(void) { // GPIO_CONFIG(20)= GPCFG_JTAG_SWCLK; // GPIO_CONFIG(21)= GPCFG_JTAG_SWDAT; systick_init(); UartxInit(UARTB); //print log delay_ms(1000); printf("\r\n *******This is IIC TEST********\n"); // I2c_Test(); //0xa0 eeprom device and write, //0x00 eeprom addr //'a' data uint8_t src_w[10]={0xa0,0x00,'a','b','c','d','e','f','g','h'}; //0xa0 eeprom device and write, //0x00 eeprom addr; //0xa1 eeprom device and read; uint8_t src_r[3]={0xa0,0x00,0xa1}; uint8_t data[9]={"None"}; data[8]='\0'; IIC_SendData(src_w,10); printf("Initial dest: %s\n", data); // delay_ms(75); IIC_ReceiveData(src_r,3,data,8); printf("End dest:%s\n", data); while(1) { } }