Jongwan Seo / Mbed 2 deprecated UART_Interrupt_Softuart_MP3

Dependencies:   mbed SoftSerial

Files at this revision

API Documentation at this revision

Comitter:
angler
Date:
Fri Apr 23 02:58:41 2021 +0000
Commit message:
F746ZG UART_Interrupt and DFPlayer with software uart(PF_13, PF_14)

Changed in this revision

DFPlayer.cpp Show annotated file Show diff for this revision Revisions of this file
DFPlayer.h Show annotated file Show diff for this revision Revisions of this file
Serial_Interrupt.cpp Show annotated file Show diff for this revision Revisions of this file
Serial_Interrupt.h Show annotated file Show diff for this revision Revisions of this file
SoftSerial.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DFPlayer.cpp	Fri Apr 23 02:58:41 2021 +0000
@@ -0,0 +1,207 @@
+#include "mbed.h"
+#include "SoftSerial.h"
+//#include "DFPlayer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+SoftSerial  mp3(PF_13, PF_14);
+
+uint8_t is_replay   =   0;
+
+uint8_t send_buf[10] = {0x7E, 0xFF, 0x06, 0x03, 00, 00, 01, 0xFE, 0xF6, 0xEF};
+
+
+void fill_uint16_bigend (uint8_t *thebuf, uint16_t data) 
+{
+    *thebuf =   (uint8_t)(data>>8);
+    *(thebuf+1) =   (uint8_t)data;
+}
+
+uint16_t mp3_get_checksum (uint8_t *thebuf) 
+{
+    uint16_t sum = 0;
+    for (int i=1; i<7; i++) {
+        sum += thebuf[i];
+    }
+    return -sum;
+}
+
+void mp3_fill_checksum () 
+{
+    uint16_t checksum = mp3_get_checksum (send_buf);
+    fill_uint16_bigend (send_buf+7, checksum);
+}
+ 
+void send_func () 
+{
+    int i;
+    for (i = 0; i < 10; i++) {
+        mp3.putc(send_buf[i]);
+//        uart8.printf("%02X ",send_buf[i]);
+    } 
+//    uart8.printf("\r\n");
+//    uart8.printf("\r\n");
+    
+}
+ 
+void mp3_send_cmd1 (uint8_t cmd, uint16_t arg) 
+{
+    send_buf[3] = cmd;
+    fill_uint16_bigend ((send_buf+5), arg);
+    mp3_fill_checksum ();
+    send_func ();
+}
+ 
+void mp3_send_cmd (uint8_t cmd) 
+{
+    send_buf[3] = cmd;
+    fill_uint16_bigend ((send_buf+5), 0);
+    mp3_fill_checksum ();
+    send_func ();
+}
+
+void mp3_set_reply (uint8_t state) 
+{
+    is_replay = state;
+    send_buf[4] = is_replay;
+}
+
+void mp3_play_physical1 (uint16_t num) 
+{
+    mp3_send_cmd1 (0x03, num);
+}
+
+void mp3_play_physical () 
+{
+    mp3_send_cmd (0x03);
+}
+ 
+void mp3_next () 
+{
+    mp3_send_cmd (0x01);
+}
+ 
+void mp3_prev () 
+{
+    mp3_send_cmd (0x02);
+}
+ 
+//0x06 set volume 0-30
+void mp3_set_volume (uint16_t volume) 
+{
+    if(volume > 30)
+    {
+        volume = 30;
+    }
+    mp3_send_cmd1 (0x06, volume);
+}
+ 
+//0x07 set EQ0/1/2/3/4/5    Normal/Pop/Rock/Jazz/Classic/Bass
+void mp3_set_EQ (uint16_t eq) 
+{
+    mp3_send_cmd1 (0x07, eq);
+}
+ 
+//0x09 set device 1/2/3/4/5 U/SD/AUX/SLEEP/FLASH
+void mp3_set_device (uint16_t device) 
+{
+    mp3_send_cmd1 (0x09, device);
+}
+ 
+void mp3_sleep () 
+{
+    mp3_send_cmd (0x0a);
+}
+ 
+void mp3_reset () 
+{
+    mp3_send_cmd (0x0c);
+}
+ 
+void mp3_play () 
+{
+    mp3_send_cmd (0x0d);
+}
+ 
+void mp3_pause () 
+{
+    mp3_send_cmd (0x0e);
+}
+ 
+void mp3_stop () 
+{
+    mp3_send_cmd (0x16);
+}
+ 
+// play mp3 file in mp3 folder in your tf card
+void mp3_play1 (uint16_t num) 
+{
+    mp3_send_cmd1 (0x12, num);
+}
+ 
+void mp3_get_state () 
+{
+    mp3_send_cmd (0x42);
+}
+ 
+void mp3_get_volume () 
+{
+    mp3_send_cmd (0x43);
+}
+ 
+void mp3_get_u_sum () 
+{
+    mp3_send_cmd (0x47);
+}
+ 
+void mp3_get_tf_sum () 
+{
+    mp3_send_cmd (0x48);
+}
+ 
+void mp3_get_flash_sum () 
+{
+    mp3_send_cmd (0x49);
+}
+ 
+void mp3_get_tf_current () 
+{
+    mp3_send_cmd (0x4c);
+}
+ 
+void mp3_get_u_current () 
+{
+    mp3_send_cmd (0x4b);
+}
+ 
+void mp3_get_flash_current () 
+{
+    mp3_send_cmd (0x4d);
+}
+ 
+void mp3_single_loop (uint8_t state) 
+{
+    mp3_send_cmd1 (0x19, !state);
+}
+ 
+void mp3_single_play (uint16_t num) 
+{
+    mp3_play1 (num);
+    wait_ms (10);
+    mp3_single_loop (true); 
+}
+ 
+void mp3_DAC (uint8_t state) 
+{
+    mp3_send_cmd1 (0x1a, !state);
+}
+ 
+void mp3_random_play () 
+{
+    mp3_send_cmd (0x18);
+}
+
+#ifdef __cplusplus
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DFPlayer.h	Fri Apr 23 02:58:41 2021 +0000
@@ -0,0 +1,45 @@
+#ifndef DFPLAYER_H
+#define DFPLAYER_H
+
+#include "SoftSerial.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void mp3_send_cmd (uint8_t cmd);
+void fill_uint16_bigend (uint8_t *thebuf, uint16_t data);
+uint16_t mp3_get_checksum (uint8_t *thebuf);
+void mp3_fill_checksum ();
+void send_func ();
+void mp3_send_cmd1 (uint8_t cmd, uint16_t arg);
+void mp3_set_reply (uint8_t state);
+void mp3_play_physical1 (uint16_t num);
+void mp3_play_physical ();
+void mp3_next ();
+void mp3_prev ();
+void mp3_set_volume (uint16_t volume);
+void mp3_set_EQ (uint16_t eq);
+void mp3_set_device (uint16_t device);
+void mp3_sleep ();
+void mp3_reset ();
+void mp3_play ();
+void mp3_pause (); 
+void mp3_stop ();
+void mp3_play1 (uint16_t num);
+void mp3_get_state ();
+void mp3_get_volume (); 
+void mp3_get_u_sum ();
+void mp3_get_tf_sum (); 
+void mp3_get_flash_sum ();
+void mp3_get_tf_current (); 
+void mp3_get_u_current ();
+void mp3_get_flash_current ();
+void mp3_single_loop (uint8_t state);
+void mp3_single_play (uint16_t num);
+void mp3_DAC (uint8_t state);
+void mp3_random_play ();
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Serial_Interrupt.cpp	Fri Apr 23 02:58:41 2021 +0000
@@ -0,0 +1,648 @@
+#include "mbed.h"
+#include "Serial_Interrupt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+Serial  uart1(TX_1, RX_1, 9600);
+Serial  uart2(TX_2, RX_2, 9600);
+Serial  uart3(TX_3, RX_3, 9600);
+Serial  uart4(TX_4, RX_4, 9600);
+Serial  uart5(TX_5, RX_5, 9600);
+Serial  uart6(TX_6, RX_6, 9600); 
+Serial  uart7(TX_7, RX_7, 9600);
+Serial  uart8(TX_8, RX_8, 115200);
+
+
+int uart1_buffer[UART_BUFFER_SIZE];
+int uart2_buffer[UART_BUFFER_SIZE];
+int uart3_buffer[UART_BUFFER_SIZE];
+int uart4_buffer[UART_BUFFER_SIZE];
+int uart5_buffer[UART_BUFFER_SIZE];
+int uart6_buffer[UART_BUFFER_SIZE];
+int uart7_buffer[UART_BUFFER_SIZE];
+int uart8_buffer[UART_BUFFER_SIZE];
+
+int uart1_rx_head = 0;
+int uart1_rx_tail = 0;
+
+int uart2_rx_head = 0;
+int uart2_rx_tail = 0;
+
+int uart3_rx_head = 0;
+int uart3_rx_tail = 0;
+
+int uart4_rx_head = 0;
+int uart4_rx_tail = 0;
+
+int uart5_rx_head = 0;
+int uart5_rx_tail = 0;
+
+int uart6_rx_head = 0;
+int uart6_rx_tail = 0;
+
+int uart7_rx_head = 0;
+int uart7_rx_tail = 0;
+
+int uart8_rx_head = 0;
+int uart8_rx_tail = 0;
+
+int uart_data1;
+int uart_data2;
+int uart_data3;
+int uart_data4;
+int uart_data5;
+int uart_data6;
+int uart_data7;
+int uart_data8;
+
+int uart1_state = 0;
+int uart1_checksum = 0;
+int uart1_distance = 0;
+float   range1 = 0;
+
+int uart2_state = 0;
+int uart2_checksum = 0;
+int uart2_distance = 0;
+float   range2 = 0;
+
+int uart3_state = 0;
+int uart3_checksum = 0;
+int uart3_distance = 0;
+float   range3 = 0;
+
+int uart4_state = 0;
+int uart4_checksum = 0;
+int uart4_distance = 0;
+float   range4 = 0;
+
+int uart5_state = 0;
+int uart5_checksum = 0;
+int uart5_distance = 0;
+float   range5 = 0;
+
+int uart6_state = 0;
+int uart6_checksum = 0;
+int uart6_distance = 0;
+float   range6 = 0;
+
+
+void Uart1RxHandler()
+{
+    while(uart1.readable())
+    {
+        write_uart1_buffer(uart1.getc());
+    }    
+}
+
+void Uart2RxHandler()
+{
+    while(uart2.readable())
+    {
+        write_uart2_buffer(uart2.getc());
+    }    
+}
+
+void Uart3RxHandler()
+{
+    while(uart3.readable())
+    {
+        write_uart3_buffer(uart3.getc());
+    }    
+}
+
+void Uart4RxHandler()
+{
+    while(uart4.readable())
+    {
+        write_uart4_buffer(uart4.getc());
+    }    
+}
+
+void Uart5RxHandler()
+{
+    while(uart5.readable())
+    {
+        write_uart5_buffer(uart5.getc());
+    }    
+}
+
+void Uart6RxHandler()
+{
+    while(uart6.readable())
+    {
+        write_uart6_buffer(uart6.getc());
+    }    
+}
+
+void Uart7RxHandler()
+{
+    while(uart7.readable())
+    {
+        write_uart7_buffer(uart7.getc());
+    }    
+}
+
+void Uart8RxHandler()
+{
+    while(uart8.readable())
+    {
+        write_uart8_buffer(uart8.getc());
+    }    
+}
+
+void range_finder_init(void)
+{
+    uart1.attach(&Uart1RxHandler, Serial::RxIrq);
+    uart2.attach(&Uart2RxHandler, Serial::RxIrq);
+    uart3.attach(&Uart3RxHandler, Serial::RxIrq);
+    uart4.attach(&Uart4RxHandler, Serial::RxIrq);
+    uart5.attach(&Uart5RxHandler, Serial::RxIrq);
+    uart6.attach(&Uart6RxHandler, Serial::RxIrq);
+    uart7.attach(&Uart7RxHandler, Serial::RxIrq);
+#ifdef DEBUG8
+    uart8.attach(&Uart8RxHandler, Serial::RxIrq);    
+#endif
+}
+
+void parse_range(void)
+{
+    uart_data1 = read_uart1();
+    if(uart_data1 != 0x00)
+    {
+#ifdef DEBUG1
+        uart8.printf("1 : 0x%02x\r\n",uart_data1);
+#endif
+        if(uart_data1 == 0xFF)
+        {
+            uart1_state = 1;
+            uart1_checksum = 0xFF;
+            uart1_distance = 0;     
+            range1 = 0;       
+        } else if(uart1_state == 1)
+        {
+            uart1_state = 2;
+            uart1_distance = uart_data1;
+            uart1_checksum += uart_data1;
+        } else if(uart1_state == 2)
+        {
+            uart1_checksum &= 0x00FF;
+            if(uart1_checksum == uart_data1)
+            {
+                uart1_state = 0;
+                range1 = uart1_distance / 10.;
+#ifdef DEBUG1
+                uart8.printf("1: %05.1f cm \r\n", range1);
+#endif
+            } else
+            {
+                uart1_state = 3;
+                uart1_distance <<= 8;
+                uart1_distance += uart_data1;
+                uart1_checksum += uart_data1;
+            }
+        } else if(uart1_state == 3)
+        {
+            uart1_checksum &= 0x00FF;
+            if(uart1_checksum == uart_data1)
+            {
+                uart1_state = 0;
+                range1 = uart1_distance / 10.;
+#ifdef DEBUG1
+                uart8.printf("1: %05.1f cm \r\n", range1);
+#endif
+            }
+        }
+        // 
+    }
+    
+    uart_data2 = read_uart2();
+    if(uart_data2 != 0x00)
+    {
+#ifdef DEBUG2
+        uart8.printf("2 : 0x%02x\r\n",uart_data2);
+#endif
+        if(uart_data2 == 0xFF)
+        {
+            uart2_state = 1;
+            uart2_checksum = 0xFF;
+            uart2_distance = 0;        
+            range2 = 0;    
+        } else if(uart2_state == 1)
+        {
+            uart2_state = 2;
+            uart2_distance = uart_data2;
+            uart2_checksum += uart_data2;
+        } else if(uart2_state == 2)
+        {
+            uart2_checksum &= 0x00FF;
+            if(uart2_checksum == uart_data2)
+            {
+                uart2_state = 0;
+                range2 = uart2_distance / 10.;
+#ifdef DEBUG2
+                uart8.printf("2: %05.1f cm \r\n", range2);
+#endif
+            } else
+            {
+                uart2_state = 3;
+                uart2_distance <<= 8;
+                uart2_distance += uart_data2;
+                uart2_checksum += uart_data2;
+            }
+        } else if(uart2_state == 3)
+        {
+            uart2_checksum &= 0x00FF;
+            if(uart2_checksum == uart_data2)
+            {
+                uart2_state = 0;
+                range2 = uart2_distance / 10.;
+#ifdef DEBUG2
+                uart8.printf("2: %05.1f cm \r\n", range2);
+#endif
+            }
+        }        // 
+    }
+    
+    uart_data3 = read_uart3();
+    if(uart_data3 != 0x00)
+    {
+#ifdef DEBUG3
+        uart8.printf("3 : 0x%02x\r\n",uart_data3);
+#endif
+        if(uart_data3 == 0xFF)
+        {
+            uart3_state = 1;
+            uart3_checksum = 0xFF;
+            uart3_distance = 0;       
+            range3 = 0;     
+        } else if(uart3_state == 1)
+        {
+            uart3_state = 2;
+            uart3_distance = uart_data3;
+            uart3_checksum += uart_data3;
+        } else if(uart3_state == 2)
+        {
+            uart3_checksum &= 0x00FF;
+            if(uart3_checksum == uart_data3)
+            {
+                uart3_state = 0;
+                range3 = uart3_distance / 10.;
+#ifdef DEBUG3
+                uart8.printf("3: %05.1f cm \r\n", range3);
+#endif
+            } else
+            {
+                uart3_state = 3;
+                uart3_distance <<= 8;
+                uart3_distance += uart_data3;
+                uart3_checksum += uart_data3;
+            }
+        } else if(uart3_state == 3)
+        {
+            uart3_checksum &= 0x00FF;
+            if(uart3_checksum == uart_data3)
+            {
+                uart3_state = 0;
+                range3 = uart3_distance / 10.;
+#ifdef DEBUG3
+                uart8.printf("3: %05.1f cm \r\n", range3);
+#endif
+            }
+        }        // 
+    }
+    
+    uart_data4 = read_uart4();
+    if(uart_data4 != 0x00)
+    {
+#ifdef DEBUG4
+        uart8.printf("4 : 0x%02x\r\n",uart_data4);
+#endif
+        if(uart_data4 == 0xFF)
+        {
+            uart4_state = 1;
+            uart4_checksum = 0xFF;
+            uart4_distance = 0;       
+            range4 = 0;     
+        } else if(uart4_state == 1)
+        {
+            uart4_state = 2;
+            uart4_distance = uart_data4;
+            uart4_checksum += uart_data4;
+        } else if(uart4_state == 2)
+        {
+            uart4_checksum &= 0x00FF;
+            if(uart4_checksum == uart_data4)
+            {
+                uart4_state = 0;
+                range4 = uart4_distance / 10.;
+#ifdef DEBUG4
+                uart8.printf("4: %05.1f cm \r\n", range4);
+#endif
+            } else
+            {
+                uart4_state = 3;
+                uart4_distance <<= 8;
+                uart4_distance += uart_data4;
+                uart4_checksum += uart_data4;
+            }
+        } else if(uart4_state == 3)
+        {
+            uart4_checksum &= 0x00FF;
+            if(uart4_checksum == uart_data4)
+            {
+                uart4_state = 0;
+                range4 = uart4_distance / 10.;
+#ifdef DEBUG4
+                uart8.printf("4: %05.1f cm \r\n", range4);
+#endif
+            }
+        }        // 
+    }
+    
+    uart_data5 = read_uart5();
+    if(uart_data5 != 0x00)
+    {
+#ifdef DEBUG5
+        uart8.printf("5 : 0x%02x\r\n",uart_data5);
+#endif
+        if(uart_data5 == 0xFF)
+        {
+            uart5_state = 1;
+            uart5_checksum = 0xFF;
+            uart5_distance = 0;       
+            range5 = 0;     
+        } else if(uart5_state == 1)
+        {
+            uart5_state = 2;
+            uart5_distance = uart_data5;
+            uart5_checksum += uart_data5;
+        } else if(uart5_state == 2)
+        {
+            uart5_checksum &= 0x00FF;
+            if(uart5_checksum == uart_data5)
+            {
+                uart5_state = 0;
+                range5 = uart5_distance / 10.;
+#ifdef DEBUG5
+                uart8.printf("5: %05.1f cm \r\n", range5);
+#endif
+            } else
+            {
+                uart5_state = 3;
+                uart5_distance <<= 8;
+                uart5_distance += uart_data5;
+                uart5_checksum += uart_data5;
+            }
+        } else if(uart5_state == 3)
+        {
+            uart5_checksum &= 0x00FF;
+            if(uart5_checksum == uart_data5)
+            {
+                uart5_state = 0;
+                range5 = uart5_distance / 10.;
+#ifdef DEBUG5
+                uart8.printf("5: %05.1f cm \r\n", range5);
+#endif
+            }
+        }        // 
+    }
+    
+    uart_data6 = read_uart6();
+    if(uart_data6 != 0x00)
+    {
+#ifdef DEBUG6
+        uart8.printf("6 : 0x%02x\r\n",uart_data6);
+#endif
+        if(uart_data6 == 0xFF)
+        {
+            uart6_state = 1;
+            uart6_checksum = 0xFF;
+            uart6_distance = 0;       
+            range6 = 0;     
+        } else if(uart6_state == 1)
+        {
+            uart6_state = 2;
+            uart6_distance = uart_data6;
+            uart6_checksum += uart_data6;
+        } else if(uart6_state == 2)
+        {
+            uart6_checksum &= 0x00FF;
+            if(uart6_checksum == uart_data6)
+            {
+                uart6_state = 0;
+                range6 = uart6_distance / 10.;
+#ifdef DEBUG6
+                uart8.printf("6: %05.1f cm \r\n", range6);
+#endif
+            } else
+            {
+                uart6_state = 3;
+                uart6_distance <<= 8;
+                uart6_distance += uart_data6;
+                uart6_checksum += uart_data6;
+            }
+        } else if(uart6_state == 3)
+        {
+            uart6_checksum &= 0x00FF;
+            if(uart6_checksum == uart_data6)
+            {
+                uart6_state = 0;
+                range6 = uart6_distance / 10.;
+#ifdef DEBUG6
+                uart8.printf("6: %05.1f cm \r\n", range6);
+#endif
+            }
+        }        // 
+    }
+    
+//    uart_data7 = read_uart7();
+//    if(uart_data7 != 0x00)
+//    {
+//#ifdef DEBUG7
+//        uart8.printf("7 : 0x%02x\r\n",uart_data7);
+//#endif        // 
+//    }
+    
+    uart_data8 = read_uart8();
+    if(uart_data8 != 0x00)
+    {
+#ifdef DEBUG8
+        uart8.printf("8 : 0x%02x\r\n",uart_data8);
+#endif        // 
+    }
+}
+
+int read_uart1(void)
+{
+    int read_data;
+    if(uart1_rx_tail == uart1_rx_head)
+    {
+        return 0;
+    } else
+    {
+        read_data = uart1_buffer[uart1_rx_tail];
+        uart1_rx_tail++;
+        uart1_rx_tail %= UART_BUFFER_SIZE;
+        return read_data;
+    }
+}
+
+int read_uart2(void)
+{
+    int read_data;
+    if(uart2_rx_tail == uart2_rx_head)
+    {
+        return 0;
+    } else
+    {
+        read_data = uart2_buffer[uart2_rx_tail];
+        uart2_rx_tail++;
+        uart2_rx_tail %= UART_BUFFER_SIZE;
+        return read_data;
+    }
+}
+
+int read_uart3(void)
+{
+    int read_data;
+    if(uart3_rx_tail == uart3_rx_head)
+    {
+        return 0;
+    } else
+    {
+        read_data = uart3_buffer[uart3_rx_tail];
+        uart3_rx_tail++;
+        uart3_rx_tail %= UART_BUFFER_SIZE;
+        return read_data;
+    }
+}
+
+int read_uart4(void)
+{
+    int read_data;
+    if(uart4_rx_tail == uart4_rx_head)
+    {
+        return 0;
+    } else
+    {
+        read_data = uart4_buffer[uart4_rx_tail];
+        uart4_rx_tail++;
+        uart4_rx_tail %= UART_BUFFER_SIZE;
+        return read_data;
+    }
+}
+
+int read_uart5(void)
+{
+    int read_data;
+    if(uart5_rx_tail == uart5_rx_head)
+    {
+        return 0;
+    } else
+    {
+        read_data = uart5_buffer[uart5_rx_tail];
+        uart5_rx_tail++;
+        uart5_rx_tail %= UART_BUFFER_SIZE;
+        return read_data;
+    }
+}
+
+int read_uart6(void)
+{
+    int read_data;
+    if(uart6_rx_tail == uart6_rx_head)
+    {
+        return 0;
+    } else
+    {
+        read_data = uart6_buffer[uart6_rx_tail];
+        uart6_rx_tail++;
+        uart6_rx_tail %= UART_BUFFER_SIZE;
+        return read_data;
+    }
+}
+
+int read_uart7(void)
+{
+    int read_data;
+    if(uart7_rx_tail == uart7_rx_head)
+    {
+        return 0;
+    } else
+    {
+        read_data = uart7_buffer[uart7_rx_tail];
+        uart7_rx_tail++;
+        uart7_rx_tail %= UART_BUFFER_SIZE;
+        return read_data;
+    }
+}
+
+int read_uart8(void)
+{
+    int read_data;
+    if(uart8_rx_tail == uart8_rx_head)
+    {
+        return 0;
+    } else
+    {
+        read_data = uart8_buffer[uart8_rx_tail];
+        uart8_rx_tail++;
+        uart8_rx_tail %= UART_BUFFER_SIZE;
+        return read_data;
+    }
+}
+
+void write_uart1_buffer(int in_data)
+{
+    uart1_buffer[uart1_rx_head++] = in_data;
+    uart1_rx_head %= UART_BUFFER_SIZE;
+}
+
+void write_uart2_buffer(int in_data)
+{
+    uart2_buffer[uart2_rx_head++] = in_data;
+    uart2_rx_head %= UART_BUFFER_SIZE;
+}
+
+void write_uart3_buffer(int in_data)
+{
+    uart3_buffer[uart3_rx_head++] = in_data;
+    uart3_rx_head %= UART_BUFFER_SIZE;
+}
+
+void write_uart4_buffer(int in_data)
+{
+    uart4_buffer[uart4_rx_head++] = in_data;
+    uart4_rx_head %= UART_BUFFER_SIZE;
+}
+
+void write_uart5_buffer(int in_data)
+{
+    uart5_buffer[uart5_rx_head++] = in_data;
+    uart5_rx_head %= UART_BUFFER_SIZE;
+}
+
+void write_uart6_buffer(int in_data)
+{
+    uart6_buffer[uart6_rx_head++] = in_data;
+    uart6_rx_head %= UART_BUFFER_SIZE;
+}
+
+void write_uart7_buffer(int in_data)
+{
+    uart7_buffer[uart7_rx_head++] = in_data;
+    uart7_rx_head %= UART_BUFFER_SIZE;
+}
+
+void write_uart8_buffer(int in_data)
+{
+    uart8_buffer[uart8_rx_head++] = in_data;
+    uart8_rx_head %= UART_BUFFER_SIZE;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Serial_Interrupt.h	Fri Apr 23 02:58:41 2021 +0000
@@ -0,0 +1,71 @@
+#ifndef SERIAL_INTERRUPT_H
+#define SERIAL_INTERRUPT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DEBUG1  1
+#define DEBUG2  1
+#define DEBUG3  1
+#define DEBUG4  1
+#define DEBUG5  1
+#define DEBUG6  1
+//#define DEBUG7  1
+#define DEBUG8  1
+
+#define TX_1    PB_6
+#define RX_1    PB_7
+#define TX_2    PD_5
+#define RX_2    PD_6
+#define TX_3    PD_8
+#define RX_3    PD_9
+#define TX_4    PC_10
+#define RX_4    PC_11
+#define TX_5    PC_12
+#define RX_5    PD_2
+#define TX_6    PC_6
+#define RX_6    PC_7
+#define TX_7    PF_7
+#define RX_7    PF_6
+#define TX_8    PE_1
+#define RX_8    PE_0
+
+#define UART_BUFFER_SIZE 16
+
+void    Uart1RxHandler();
+void    Uart2RxHandler();
+void    Uart3RxHandler();
+void    Uart4RxHandler();
+void    Uart5RxHandler();
+void    Uart6RxHandler();
+void    Uart7RxHandler();
+void    Uart8RxHandler();
+
+void    write_uart1_buffer(int in_data);
+void    write_uart2_buffer(int in_data);
+void    write_uart3_buffer(int in_data);
+void    write_uart4_buffer(int in_data);
+void    write_uart5_buffer(int in_data);
+void    write_uart6_buffer(int in_data);
+void    write_uart7_buffer(int in_data);
+void    write_uart8_buffer(int in_data);
+
+int read_uart1(void);
+int read_uart2(void);
+int read_uart3(void);
+int read_uart4(void);
+int read_uart5(void);
+int read_uart6(void);
+int read_uart7(void);
+int read_uart8(void);
+
+void    range_finder_init(void);
+void    parse_range(void);
+void    read_nano(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoftSerial.lib	Fri Apr 23 02:58:41 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Sissors/code/SoftSerial/#a0029614de72
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 23 02:58:41 2021 +0000
@@ -0,0 +1,21 @@
+#include "mbed.h"
+#include "DFPlayer.h"
+#include "Serial_Interrupt.h"
+
+uint16_t    loop_count   =   0;
+
+int main(void)
+{
+    wait(2);
+    range_finder_init();
+    mp3_set_volume(5);
+    wait(1);
+    mp3_play_physical1(3);
+    wait(1);
+    
+   
+    while (true) 
+    {
+        parse_range();
+    }    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Apr 23 02:58:41 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file