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
Fork of minimal_i2c_mother by
master.cpp
- Committer:
- nghansen
- Date:
- 2014-11-20
- Revision:
- 0:d3bdf717512e
- Child:
- 1:92677fbab5f1
File content as of revision 0:d3bdf717512e:
#include "mbed.h"
I2C Bus(p28, p27);
int slaveAddress;
Serial Usb(USBTX, USBRX);
char buffer[16] = {'T', 'e', 's', 't', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int ack;
DigitalOut sent(LED1);
DigitalOut received(LED2);
void resetBus()
{
Bus.stop();
Bus.start();
return;
}
int main()
{
slaveAddress = 0x02;
resetBus();
while (1)
{
for(int i = 0; i < sizeof buffer; buffer[i++]=0x00);
Usb.scanf("%s", buffer);
Usb.printf("%s \n\r", buffer);
ack = Bus.write(slaveAddress & 0xFE, buffer, 16);
if(ack == 0)
Usb.printf(" ...Ack \n\r");
ack = Bus.write(0, buffer, 16);
if(ack == 0)
Usb.printf("Ack from broadcast \n\r");
Bus.read(slaveAddress | 1, buffer, 16, 0);
Usb.printf("Received: %s \n\r", buffer);
}
}
