SerialRxInterrupt

Dependencies:   mbed

Fork of SerialReceiveInterrupt by Doug Wendelboe

Committer:
thinkfire
Date:
Fri Jan 20 11:49:15 2017 +0000
Revision:
1:6fb6fabd8592
Parent:
0:444ff736d35e
tested

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YouTahDoug 0:444ff736d35e 1 //*****************************************************************************
YouTahDoug 0:444ff736d35e 2 //* SERIAL PORT RECEIVE ATTACH DEMO PROGRAM
YouTahDoug 0:444ff736d35e 3 //* Simple demo program showing how the serial port "attach()" method is used
YouTahDoug 0:444ff736d35e 4 //* to interrupt when a character has been received into the USART.
YouTahDoug 0:444ff736d35e 5 //*
YouTahDoug 0:444ff736d35e 6 //* The main() program sets up the serial port baudrate, attaches the
YouTahDoug 0:444ff736d35e 7 //* function pointer to the function to be called when a character is received
YouTahDoug 0:444ff736d35e 8 //* on this serial port, and then loops and flashed some LEDs.
YouTahDoug 0:444ff736d35e 9 //*
YouTahDoug 0:444ff736d35e 10 //* Routine "void SerialRecvInterrupt(void)" is invoked anytime a character
YouTahDoug 0:444ff736d35e 11 //* has been received by the by the USART.
YouTahDoug 0:444ff736d35e 12 //*
YouTahDoug 0:444ff736d35e 13 //*****************************************************************************
YouTahDoug 0:444ff736d35e 14 #include "mbed.h"
YouTahDoug 0:444ff736d35e 15 #include <ctype.h>
YouTahDoug 0:444ff736d35e 16
YouTahDoug 0:444ff736d35e 17 #define BFR_SIZE 32 // Needs to be a power of two.
YouTahDoug 0:444ff736d35e 18 #define BFR_WRAP_MASK 0x1F // Modulo 32
YouTahDoug 0:444ff736d35e 19
YouTahDoug 0:444ff736d35e 20 unsigned char rcvBuffer[BFR_SIZE]; // Receive buffer.
YouTahDoug 0:444ff736d35e 21 unsigned char inIdx; // Read by background, written by Int Handler.
YouTahDoug 0:444ff736d35e 22 unsigned char outIdx; // Read by Int Handler, written by Background.
YouTahDoug 0:444ff736d35e 23
thinkfire 1:6fb6fabd8592 24 DigitalOut led4(LED4);
thinkfire 1:6fb6fabd8592 25 Serial usbS(USBTX,USBRX);
thinkfire 1:6fb6fabd8592 26 Serial pins(p9,p10);
YouTahDoug 0:444ff736d35e 27
YouTahDoug 0:444ff736d35e 28 //*****************************************************************************
YouTahDoug 0:444ff736d35e 29 // mc serial receive interrupt handler
YouTahDoug 0:444ff736d35e 30 //*****************************************************************************
thinkfire 1:6fb6fabd8592 31 void rx_interrupt(void) {
thinkfire 1:6fb6fabd8592 32 char c;
thinkfire 1:6fb6fabd8592 33 led4 = 1;
thinkfire 1:6fb6fabd8592 34 usbS.printf("Ack Recieved from Module\n");
thinkfire 1:6fb6fabd8592 35 c=pins.getc();
thinkfire 1:6fb6fabd8592 36 c=pins.getc();
YouTahDoug 0:444ff736d35e 37 }
YouTahDoug 0:444ff736d35e 38 //*****************************************************************************
YouTahDoug 0:444ff736d35e 39 // Main Program
YouTahDoug 0:444ff736d35e 40 //*****************************************************************************
YouTahDoug 0:444ff736d35e 41
YouTahDoug 0:444ff736d35e 42 int main() {
thinkfire 1:6fb6fabd8592 43 int adc_val = rand()%100+1;
thinkfire 1:6fb6fabd8592 44 char msg[30];
YouTahDoug 0:444ff736d35e 45
thinkfire 1:6fb6fabd8592 46 usbS.printf("Msg Send to Module\n");
thinkfire 1:6fb6fabd8592 47 pins.attach(&rx_interrupt,pins.RxIrq);
YouTahDoug 0:444ff736d35e 48
thinkfire 1:6fb6fabd8592 49
YouTahDoug 0:444ff736d35e 50 while(1) {
thinkfire 1:6fb6fabd8592 51 sprintf(msg,"Adc_val %d\n",adc_val);
thinkfire 1:6fb6fabd8592 52 while(!pins.writeable());
thinkfire 1:6fb6fabd8592 53 pins.puts(msg);
thinkfire 1:6fb6fabd8592 54 wait(2);
thinkfire 1:6fb6fabd8592 55 led4 = 0;
YouTahDoug 0:444ff736d35e 56 }
YouTahDoug 0:444ff736d35e 57 }