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.
Dependencies: mbed
Revision 0:a9d57902bf67, committed 2015-02-05
- Comitter:
- RedBearLab
- Date:
- Thu Feb 05 03:16:51 2015 +0000
- Child:
- 1:b6853f8b28d1
- Commit message:
- Mbed i2c library demo with at24cxxx on Readbear nRF51822
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Feb 05 03:16:51 2015 +0000
@@ -0,0 +1,88 @@
+
+#include "mbed.h"
+
+#define DEV_ADDR 0xA0
+
+I2C i2c(P0_29, P0_28);
+Serial pc(USBTX, USBRX);
+
+/**********************************************************************
+* @brief : Write data to AT24C512
+*
+* @param[in] addr : The address of stored
+* @param[in] *pbuf : The pointer of data
+* @param[in] length : The length of data
+*
+* @return none
+**********************************************************************/
+void AT24C512_WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t length)
+{
+ char buf[length+2];
+ buf[0] = (uint8_t)(addr>>8);
+ buf[1] = (uint8_t)(addr);
+ memcpy(&buf[2], pbuf, length);
+ i2c.write(DEV_ADDR, buf, length+2, false);
+}
+/**********************************************************************
+* @brief : Read data from AT24C512
+*
+* @param[in] addr : The address of read in AT24C512
+* @param[out] *pbuf : The pointer of buffer
+* @param[in] length : The length of data
+*
+* @return none
+**********************************************************************/
+void AT24C512_ReadBytes(uint16_t addr, uint8_t *pbuf, uint16_t length)
+{
+ char buf[2];
+ buf[0] = (uint8_t)(addr>>8);
+ buf[1] = (uint8_t)(addr);
+ i2c.write(DEV_ADDR, buf, 2, false);
+
+ i2c.read(DEV_ADDR, (char *)pbuf, length, false);
+}
+
+
+uint8_t w_buf[11]={'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd', '!'};
+uint8_t r_buf[11];
+
+
+int main(void)
+{
+ uint8_t index;
+
+ pc.baud(9600);
+ pc.printf("IIC Demo Start \r\n");
+
+ while(1)
+ {
+ wait(2);
+ AT24C512_WriteBytes(0, w_buf, 11);
+ wait(0.5);
+ AT24C512_ReadBytes(0, r_buf, 11);
+ for(index=0; index<11; index++)
+ pc.putc(r_buf[index]);
+
+ pc.printf("\r\n");
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 05 03:16:51 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e188a91d3eaa \ No newline at end of file