![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test
main.cpp@46:9993fb18e36f, 2019-07-05 (annotated)
- Committer:
- zvone141
- Date:
- Fri Jul 05 10:14:17 2019 +0000
- Revision:
- 46:9993fb18e36f
- Parent:
- 45:092347ceac92
Fix RTS pin, added delay.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
3:2757d7abb7d9 | 1 | #include "mbed.h" |
Jonathan Austin |
3:2757d7abb7d9 | 2 | |
gorazdko | 43:c179810e1a75 | 3 | |
gorazdko | 43:c179810e1a75 | 4 | |
gorazdko | 43:c179810e1a75 | 5 | #define TYPE_MEASEUREMENT 0xA |
gorazdko | 43:c179810e1a75 | 6 | |
gorazdko | 43:c179810e1a75 | 7 | |
gorazdko | 43:c179810e1a75 | 8 | #define ST_TX D1 |
gorazdko | 43:c179810e1a75 | 9 | #define ST_RX D0 |
zvone141 | 46:9993fb18e36f | 10 | #define RTS D14 |
gorazdko | 43:c179810e1a75 | 11 | |
gorazdko | 43:c179810e1a75 | 12 | |
gorazdko | 43:c179810e1a75 | 13 | |
Jonathan Austin |
3:2757d7abb7d9 | 14 | DigitalOut led1(LED1); |
gorazdko | 43:c179810e1a75 | 15 | Serial pc(USBTX, USBRX, NULL, 115200); // tx, rx |
gorazdko | 43:c179810e1a75 | 16 | DigitalIn pin_rts(RTS); |
gorazdko | 43:c179810e1a75 | 17 | DigitalIn button(USER_BUTTON); |
gorazdko | 43:c179810e1a75 | 18 | Serial st_uart(ST_TX, ST_RX, NULL, 115200); // tx, rx |
Jonathan Austin |
3:2757d7abb7d9 | 19 | |
gorazdko | 43:c179810e1a75 | 20 | |
gorazdko | 43:c179810e1a75 | 21 | |
gorazdko | 43:c179810e1a75 | 22 | uint8_t test_vector[10000]; |
gorazdko | 43:c179810e1a75 | 23 | |
gorazdko | 43:c179810e1a75 | 24 | |
gorazdko | 43:c179810e1a75 | 25 | void uart_busy_check(void) |
gorazdko | 43:c179810e1a75 | 26 | { |
gorazdko | 43:c179810e1a75 | 27 | while (pin_rts == 0) |
gorazdko | 43:c179810e1a75 | 28 | { |
gorazdko | 43:c179810e1a75 | 29 | // do nothing |
gorazdko | 43:c179810e1a75 | 30 | led1=0; |
gorazdko | 43:c179810e1a75 | 31 | } |
gorazdko | 43:c179810e1a75 | 32 | } |
gorazdko | 43:c179810e1a75 | 33 | |
gorazdko | 43:c179810e1a75 | 34 | |
gorazdko | 43:c179810e1a75 | 35 | void write_sample(uint16_t sample) |
gorazdko | 43:c179810e1a75 | 36 | { |
gorazdko | 43:c179810e1a75 | 37 | led1=1; |
gorazdko | 43:c179810e1a75 | 38 | |
gorazdko | 43:c179810e1a75 | 39 | uint8_t byte_little = ((uint8_t *)&sample)[0]; |
gorazdko | 43:c179810e1a75 | 40 | uint8_t byte_big = ((uint8_t *)&sample)[1]; |
gorazdko | 43:c179810e1a75 | 41 | |
gorazdko | 43:c179810e1a75 | 42 | st_uart.putc(byte_little); |
gorazdko | 43:c179810e1a75 | 43 | st_uart.putc(byte_big); |
gorazdko | 43:c179810e1a75 | 44 | |
gorazdko | 43:c179810e1a75 | 45 | uart_busy_check(); |
gorazdko | 43:c179810e1a75 | 46 | } |
gorazdko | 43:c179810e1a75 | 47 | |
Jonathan Austin |
3:2757d7abb7d9 | 48 | int main() { |
gorazdko | 43:c179810e1a75 | 49 | |
gorazdko | 43:c179810e1a75 | 50 | led1=1; |
gorazdko | 43:c179810e1a75 | 51 | pc.printf("About to simulate data over the second uart D1 (Tx), D0 (Rx) - **Press button**... \n\r"); |
gorazdko | 43:c179810e1a75 | 52 | |
gorazdko | 43:c179810e1a75 | 53 | while (!button) |
gorazdko | 43:c179810e1a75 | 54 | { |
gorazdko | 43:c179810e1a75 | 55 | |
gorazdko | 43:c179810e1a75 | 56 | } |
gorazdko | 43:c179810e1a75 | 57 | |
gorazdko | 43:c179810e1a75 | 58 | pc.printf("Button pressed! Starting..."); |
gorazdko | 43:c179810e1a75 | 59 | |
gorazdko | 43:c179810e1a75 | 60 | while(1) |
gorazdko | 43:c179810e1a75 | 61 | { |
gorazdko | 43:c179810e1a75 | 62 | |
gorazdko | 43:c179810e1a75 | 63 | /* simulate data */ |
gorazdko | 44:3b8a8dba7998 | 64 | for (uint16_t i=0; i<10; i++) |
gorazdko | 43:c179810e1a75 | 65 | { |
gorazdko | 43:c179810e1a75 | 66 | st_uart.putc(TYPE_MEASEUREMENT); |
gorazdko | 43:c179810e1a75 | 67 | st_uart.putc(0x00); /* CRC */ |
gorazdko | 44:3b8a8dba7998 | 68 | |
gorazdko | 44:3b8a8dba7998 | 69 | if (i<9) |
gorazdko | 44:3b8a8dba7998 | 70 | st_uart.putc(i); /* INDEX (incrementing) */ |
gorazdko | 44:3b8a8dba7998 | 71 | else |
gorazdko | 44:3b8a8dba7998 | 72 | st_uart.putc(255); /* end of measurement 255 (0xff) */ |
gorazdko | 44:3b8a8dba7998 | 73 | |
gorazdko | 45:092347ceac92 | 74 | /* SIZE OF SAMPLES 5000 == 10000 bytes */ |
zvone141 | 46:9993fb18e36f | 75 | uint16_t size_of_samples = 2500; |
gorazdko | 45:092347ceac92 | 76 | uint8_t byte_little = ((uint8_t *)&size_of_samples)[0]; |
gorazdko | 45:092347ceac92 | 77 | uint8_t byte_big = ((uint8_t *)&size_of_samples)[1]; |
gorazdko | 45:092347ceac92 | 78 | st_uart.putc(byte_little); |
gorazdko | 45:092347ceac92 | 79 | st_uart.putc(byte_big); |
gorazdko | 43:c179810e1a75 | 80 | |
zvone141 | 46:9993fb18e36f | 81 | for (int i=0; i<5000; i+=2) |
gorazdko | 43:c179810e1a75 | 82 | { |
gorazdko | 43:c179810e1a75 | 83 | write_sample(i); |
gorazdko | 43:c179810e1a75 | 84 | } |
gorazdko | 43:c179810e1a75 | 85 | |
gorazdko | 43:c179810e1a75 | 86 | } |
gorazdko | 43:c179810e1a75 | 87 | |
zvone141 | 46:9993fb18e36f | 88 | wait(3.5); |
zvone141 | 46:9993fb18e36f | 89 | |
Jonathan Austin |
3:2757d7abb7d9 | 90 | } |
Jonathan Austin |
3:2757d7abb7d9 | 91 | } |