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.
Fork of I2C_HelloWorld_Mbed by
main.cpp
- Committer:
- marcus255
- Date:
- 2015-12-15
- Revision:
- 6:35640814d53b
- Parent:
- 5:759439e9e976
- Child:
- 7:04a1f5398882
File content as of revision 6:35640814d53b:
// Conv2 Master
#include "main.h"
int main() {
init();
//conv2.printf("conv2 says: Hello World!\n\r");
while (1) {}
}
void onUartChar(){
NVIC_DisableIRQ(UART0_IRQn);
if (conv2.getc() == DATA_TO_WRITE_CHAR){
char received = conv2.getc();
//conv2.putc(received);
if (received == SLAVE_ADDR){ // writing to slave
if (!transmission) {
i2c.start();
transmission = 1;
}
if (i2c.write((int)received))
conv2.putc(UART_CONFIRMATION_CHAR);
else {
conv2.putc(UART_NON_CONFIRMATION_CHAR);
}
while (conv2.getc() == DATA_TO_WRITE_CHAR){
received = conv2.getc();
if (i2c.write((int)received))
conv2.putc(UART_CONFIRMATION_CHAR);
else {
conv2.putc(UART_NON_CONFIRMATION_CHAR);
break;
}
}
}
else if (received == (SLAVE_ADDR | 0x01)){ // reading from slave
char rec;
if (!transmission) {
i2c.start();
transmission = 1;
}
if (i2c.write((int)rec)){
//conv2.putc(UART_CHAR_INCOMING);
while (conv2.getc() == DATA_TO_READ_CHAR){
rec = (char)i2c.read(1);
conv2.putc(UART_CHAR_INCOMING);
conv2.putc(rec);
}
i2c.read(0);
}
else {
conv2.putc(UART_NON_CONFIRMATION_CHAR);
}
conv2.putc(END_OF_TRANSMISSION);
}
}
// i2c.stop();
transmission = 0;
NVIC_EnableIRQ(UART0_IRQn);
}
void init(void){
i2c.frequency(100000);
conv2.baud(921600);
conv2.attach(&onUartChar);
}
