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.
main.cpp
00001 #include "mbed.h" 00002 00003 00004 00005 #define TYPE_MEASEUREMENT 0xA 00006 00007 00008 #define ST_TX D1 00009 #define ST_RX D0 00010 #define RTS D15 00011 00012 00013 00014 DigitalOut led1(LED1); 00015 Serial pc(USBTX, USBRX, NULL, 115200); // tx, rx 00016 DigitalIn pin_rts(RTS); 00017 DigitalIn button(USER_BUTTON); 00018 Serial st_uart(ST_TX, ST_RX, NULL, 115200); // tx, rx 00019 00020 00021 00022 uint8_t test_vector[10000]; 00023 00024 00025 void uart_busy_check(void) 00026 { 00027 while (pin_rts == 0) 00028 { 00029 // do nothing 00030 led1=0; 00031 } 00032 } 00033 00034 00035 void write_sample(uint16_t sample) 00036 { 00037 led1=1; 00038 00039 uint8_t byte_little = ((uint8_t *)&sample)[0]; 00040 uint8_t byte_big = ((uint8_t *)&sample)[1]; 00041 00042 st_uart.putc(byte_little); 00043 st_uart.putc(byte_big); 00044 00045 uart_busy_check(); 00046 } 00047 00048 int main() { 00049 00050 led1=1; 00051 pc.printf("About to simulate data over the second uart D1 (Tx), D0 (Rx) - **Press button**... \n\r"); 00052 00053 while (!button) 00054 { 00055 00056 } 00057 00058 pc.printf("Button pressed! Starting..."); 00059 00060 while(1) 00061 { 00062 00063 /* simulate data */ 00064 for (uint16_t i=0; i<10; i++) 00065 { 00066 st_uart.putc(TYPE_MEASEUREMENT); 00067 st_uart.putc(0x00); /* CRC */ 00068 00069 if (i<9) 00070 st_uart.putc(i); /* INDEX (incrementing) */ 00071 else 00072 st_uart.putc(255); /* end of measurement 255 (0xff) */ 00073 00074 /* SIZE OF SAMPLES 5000 == 10000 bytes */ 00075 uint16_t size_of_samples = 5000; 00076 uint8_t byte_little = ((uint8_t *)&size_of_samples)[0]; 00077 uint8_t byte_big = ((uint8_t *)&size_of_samples)[1]; 00078 st_uart.putc(byte_little); 00079 st_uart.putc(byte_big); 00080 00081 for (int i=0; i<5000; i++) 00082 { 00083 write_sample(i); 00084 } 00085 00086 } 00087 00088 } 00089 }
Generated on Wed Jul 27 2022 20:36:01 by
1.7.2