Marek Trojan
/
_8_CONV_2_MASTER
program for conv2
Fork of I2C_HelloWorld_Mbed by
main.cpp
- Committer:
- marcus255
- Date:
- 2015-12-01
- Revision:
- 4:35e714396141
- Parent:
- 3:df6232c70efd
- Child:
- 5:759439e9e976
File content as of revision 4:35e714396141:
// 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_CONFIRMATION_CHAR); else { conv2.putc(UART_NON_CONFIRMATION_CHAR); } while (conv2.getc() == DATA_TO_READ_CHAR){ rec = (char)i2c.read(1); conv2.putc(UART_CHAR_INCOMING); conv2.putc(rec); } }/* else{ conv2.putc((char)0x12); } */ } /* while (conv2.getc() == DATA_TO_WRITE_CHAR){ char received = conv2.getc(); if (received & 0x01 == 0x00){ // 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); break; } } else if (received & 0x01 == 0x01){ // reading from slave } else{} } */ /*if (first_rec == DATA_TO_READ_CHAR){ char sec_rec = conv2.getc(); if (i2c.write((int)sec_rec)) conv2.putc(UART_CONFIRMATION_CHAR); else { conv2.putc(UART_NON_CONFIRMATION_CHAR); break; } while (conv2.getc()) == DATA_TO_READ_CHAR){ } }*/ i2c.stop(); transmission = 0; NVIC_EnableIRQ(UART0_IRQn); } void init(void){ i2c.frequency(100000); conv2.baud(921600); conv2.attach(&onUartChar); }