Levi Vohland / Mbed 2 deprecated mbed_AFDAU

Dependencies:   mbed

Committer:
VohlandL
Date:
Mon Dec 10 11:13:56 2018 +0000
Revision:
0:341db01762fe
Child:
1:6cb1e26cf1ff
I2C Arduino Slave Receive Test - Successful; -8bit address required for I2C (slave address << 1); -first byte received over I2C is corrupted(?). Always 79. Fixed by receiving 3 bytes with the first as a dummy. Internet says possibly delay in connect.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
VohlandL 0:341db01762fe 1 #include "mbed.h"
VohlandL 0:341db01762fe 2
VohlandL 0:341db01762fe 3 // assign I2C pins
VohlandL 0:341db01762fe 4 int I2C_adr = 0x27 << 1;
VohlandL 0:341db01762fe 5
VohlandL 0:341db01762fe 6 // initialise
VohlandL 0:341db01762fe 7 char C39_data[3] = {0, 255, 255};
VohlandL 0:341db01762fe 8 int instWeight = 0;
VohlandL 0:341db01762fe 9
VohlandL 0:341db01762fe 10 //Set up serial and I2C connections
VohlandL 0:341db01762fe 11 Serial pc(USBTX, USBRX);
VohlandL 0:341db01762fe 12 I2C i2c(p9, p10);
VohlandL 0:341db01762fe 13
VohlandL 0:341db01762fe 14 int main() {
VohlandL 0:341db01762fe 15
VohlandL 0:341db01762fe 16 while(1){
VohlandL 0:341db01762fe 17 i2c.read(I2C_adr, C39_data, 3);
VohlandL 0:341db01762fe 18
VohlandL 0:341db01762fe 19 if (C39_data[1] < 255) {
VohlandL 0:341db01762fe 20 instWeight = C39_data[1] << 8;
VohlandL 0:341db01762fe 21 instWeight = instWeight | C39_data[2];
VohlandL 0:341db01762fe 22 pc.printf("%d\n",instWeight);
VohlandL 0:341db01762fe 23 }
VohlandL 0:341db01762fe 24 }
VohlandL 0:341db01762fe 25 }