Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #define DEV_ADDR 0xAE 00003 00004 I2C i2c(PB_11, PB_10); 00005 Serial pc(PA_2, PA_3); 00006 AnalogIn FWD(PA_0); 00007 AnalogIn REF(PA_1); 00008 00009 void AT24C32_WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t length) 00010 { 00011 char buf[length+2]; 00012 buf[0] = (uint8_t)(addr>>8); 00013 buf[1] = (uint8_t)(addr); 00014 memcpy(&buf[2], pbuf, length); 00015 i2c.write(DEV_ADDR, buf, length+2, false); 00016 } 00017 00018 void AT24C32_ReadBytes(uint16_t addr, uint8_t *pbuf, uint16_t length) 00019 { 00020 char buf[2]; 00021 buf[0] = (uint8_t)(addr>>8); 00022 buf[1] = (uint8_t)(addr); 00023 i2c.write(DEV_ADDR, buf, 2, false); 00024 00025 i2c.read(DEV_ADDR, (char *)pbuf, length, false); 00026 } 00027 00028 float measure_REF; 00029 00030 uint8_t w_buf[1]; 00031 uint8_t r_buf[1]; 00032 uint8_t byte =0; 00033 int addr=0x00; 00034 char Data=0; 00035 int main(void) 00036 { 00037 uint8_t index=0; 00038 00039 00040 pc.baud(9600); 00041 pc.printf("IIC Demo Start \r\n"); 00042 00043 while(1) 00044 { 00045 //WRITE************************************** 00046 00047 uint8_t byte = REF.read_u16() >> 8; 00048 pc.printf("EEPROM Write Byte= %d\n",byte); 00049 AT24C32_WriteBytes(addr,&byte,1); 00050 //******************************************* 00051 00052 //READ*************************************** 00053 wait(1); 00054 AT24C32_ReadBytes(addr, r_buf,1); 00055 for(index=0; index<1; index++) 00056 Data=(r_buf[index]); 00057 pc.printf("EEPROM Read Byte=%d\n",Data); 00058 00059 } 00060 }
Generated on Thu Jul 14 2022 19:00:45 by
1.7.2