![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Looking up interrupts from MaxBotix Maxsonar MB73x0 ultrasonic gauge and writing data and timestamp to SD flash card. I'm using MB7380 with STM32F103C8T6 minimal board from Ali (it's perfect MCU board for small projects!).
Dependencies: SDFileSystem mbed
main.cpp@0:2ce0698a332d, 2016-03-14 (annotated)
- Committer:
- shtirlitz
- Date:
- Mon Mar 14 21:26:39 2016 +0000
- Revision:
- 0:2ce0698a332d
- Child:
- 1:5c9bde92518d
???????? ?????? ??????? ?? PA9/PA10 ?? ?????????? ? ?????? ? PA2/PA3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shtirlitz | 0:2ce0698a332d | 1 | #include "mbed.h" |
shtirlitz | 0:2ce0698a332d | 2 | |
shtirlitz | 0:2ce0698a332d | 3 | Serial pc(PA_2, PA_3); // This is USB tx, rx |
shtirlitz | 0:2ce0698a332d | 4 | Serial sensor_uart(PA_9, PA_10); // This is USART2 tx, rx |
shtirlitz | 0:2ce0698a332d | 5 | |
shtirlitz | 0:2ce0698a332d | 6 | DigitalOut myled(PB_5); // This is USER LED |
shtirlitz | 0:2ce0698a332d | 7 | DigitalOut myled2(PA_7); // This is USER LED |
shtirlitz | 0:2ce0698a332d | 8 | DigitalIn BlueButton(PB_9); // This is Blue-Button |
shtirlitz | 0:2ce0698a332d | 9 | |
shtirlitz | 0:2ce0698a332d | 10 | #define Pressed 0 |
shtirlitz | 0:2ce0698a332d | 11 | #define NotPressed 1 |
shtirlitz | 0:2ce0698a332d | 12 | |
shtirlitz | 0:2ce0698a332d | 13 | int USBByte='\0'; |
shtirlitz | 0:2ce0698a332d | 14 | int GaugeByte='\0'; |
shtirlitz | 0:2ce0698a332d | 15 | int n=0; |
shtirlitz | 0:2ce0698a332d | 16 | int readgauge = 0; |
shtirlitz | 0:2ce0698a332d | 17 | Timer t; |
shtirlitz | 0:2ce0698a332d | 18 | char str[5]; |
shtirlitz | 0:2ce0698a332d | 19 | long millis = 0; |
shtirlitz | 0:2ce0698a332d | 20 | |
shtirlitz | 0:2ce0698a332d | 21 | void PC_INT() // USART2 used for Debug |
shtirlitz | 0:2ce0698a332d | 22 | { |
shtirlitz | 0:2ce0698a332d | 23 | // Note: you need to actually read from the serial to clear the RX interrupt |
shtirlitz | 0:2ce0698a332d | 24 | pc.putc(pc.getc()); |
shtirlitz | 0:2ce0698a332d | 25 | myled = (myled)?(0):(1); |
shtirlitz | 0:2ce0698a332d | 26 | } |
shtirlitz | 0:2ce0698a332d | 27 | |
shtirlitz | 0:2ce0698a332d | 28 | void SENSOR_USART_INT() // SENSOR_USART |
shtirlitz | 0:2ce0698a332d | 29 | { |
shtirlitz | 0:2ce0698a332d | 30 | // Note: you need to actually read from the serial to clear the RX interrupt |
shtirlitz | 0:2ce0698a332d | 31 | //myled = 1; |
shtirlitz | 0:2ce0698a332d | 32 | //Serial3.scanf(str); |
shtirlitz | 0:2ce0698a332d | 33 | //sensor_uart.scanf("%5s", str); |
shtirlitz | 0:2ce0698a332d | 34 | //str = strcat (" PISKA ", str); |
shtirlitz | 0:2ce0698a332d | 35 | //sprintf(millis, "%d", t.read_ms()); |
shtirlitz | 0:2ce0698a332d | 36 | //int k = 0; |
shtirlitz | 0:2ce0698a332d | 37 | //for (k = 0; k < 10; k++){;} |
shtirlitz | 0:2ce0698a332d | 38 | //str = strcat (millis, str); |
shtirlitz | 0:2ce0698a332d | 39 | //pc.printf(str); |
shtirlitz | 0:2ce0698a332d | 40 | //pc.printf(millis); |
shtirlitz | 0:2ce0698a332d | 41 | if (sensor_uart.getc() == 'R') { |
shtirlitz | 0:2ce0698a332d | 42 | myled = (myled)?(0):(1); |
shtirlitz | 0:2ce0698a332d | 43 | pc.printf("timestamp: %d; gauge value: %s\r\n", t.read_ms(), sensor_uart.gets(str, 5)); |
shtirlitz | 0:2ce0698a332d | 44 | } |
shtirlitz | 0:2ce0698a332d | 45 | } |
shtirlitz | 0:2ce0698a332d | 46 | |
shtirlitz | 0:2ce0698a332d | 47 | int main() |
shtirlitz | 0:2ce0698a332d | 48 | { |
shtirlitz | 0:2ce0698a332d | 49 | myled = 0; |
shtirlitz | 0:2ce0698a332d | 50 | |
shtirlitz | 0:2ce0698a332d | 51 | // SetUp the baud rate |
shtirlitz | 0:2ce0698a332d | 52 | pc.baud(9600); |
shtirlitz | 0:2ce0698a332d | 53 | sensor_uart.baud(9600); |
shtirlitz | 0:2ce0698a332d | 54 | |
shtirlitz | 0:2ce0698a332d | 55 | sensor_uart.attach(&SENSOR_USART_INT); |
shtirlitz | 0:2ce0698a332d | 56 | pc.attach(&PC_INT); |
shtirlitz | 0:2ce0698a332d | 57 | |
shtirlitz | 0:2ce0698a332d | 58 | t.start(); |
shtirlitz | 0:2ce0698a332d | 59 | |
shtirlitz | 0:2ce0698a332d | 60 | pc.printf("\n\r\n\r|||||START MAIN|||||\n\r"); |
shtirlitz | 0:2ce0698a332d | 61 | |
shtirlitz | 0:2ce0698a332d | 62 | while(1) { |
shtirlitz | 0:2ce0698a332d | 63 | // Test the Blue Button |
shtirlitz | 0:2ce0698a332d | 64 | while(BlueButton == Pressed) { |
shtirlitz | 0:2ce0698a332d | 65 | myled2 = BlueButton; |
shtirlitz | 0:2ce0698a332d | 66 | pc.printf("Please release the BLUE Button\n\r"); |
shtirlitz | 0:2ce0698a332d | 67 | } |
shtirlitz | 0:2ce0698a332d | 68 | } |
shtirlitz | 0:2ce0698a332d | 69 | } |