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
COMM-RxTx.cpp
- Committer:
- pinofal
- Date:
- 2022-05-03
- Revision:
- 3:d63922c90649
File content as of revision 3:d63922c90649:
#include "mbed.h"
DigitalOut led(LED1);
DigitalOut Din(PB_9);
Serial pc(USBTX, USBRX, 9600); // seriale di comunicazione con il PC. Associati a PA_11 e PA_12
// carattere in arrivo dal PC
volatile unsigned char cReadChar;
void RxInterrupt(void)
{
// ricevi caratteri su seriale, se disponibili
while((pc.readable()))
{
// leggi carattere e riscrivi carattere su UART
cReadChar = pc.getc();
pc.printf("\r\nRx [CHAR]: %c\n\r",cReadChar);
pc.printf("Rx [HEX]: %#x\n\r", cReadChar);
pc.printf("Rx [reverse BIN]: ");
for(int i = 0; i< 8; i++)
pc.printf("%d",((cReadChar>>i)&0x01));
pc.printf("\n\r");
}
}
//+++++++++
// MAIN
//+++++++++
int main()
{
pc.printf("\n\r*** Welcome TxRx ***\n\r");
// definisci callback di IRQ
pc.attach(&RxInterrupt,Serial::RxIrq);
// ciclo main
while(true)
{
led = !led; // Toggle LED
wait_ms(500);
}
}