fork frdm kl25z slave
Revision 8:aa64e731174a, committed 2022-04-01
- Comitter:
- jlsalvat
- Date:
- Fri Apr 01 17:35:58 2022 +0000
- Parent:
- 7:be466464a18c
- Commit message:
- change for frdm-kl25Z
Changed in this revision
portserial.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r be466464a18c -r aa64e731174a portserial.cpp --- a/portserial.cpp Fri Oct 06 02:54:27 2017 +0000 +++ b/portserial.cpp Fri Apr 01 17:35:58 2022 +0000 @@ -29,6 +29,8 @@ #include "mb.h" #include "mbport.h" +#define INPUT 0 +#define OUTPUT 1 /* ----------------------- static functions ---------------------------------*/ static void prvvUARTTxReadyISR( void ); @@ -57,10 +59,13 @@ #elif defined(TARGET_NUMAKER_PFM_M487) // for M478 board Serial pc(PC_12, PC_11); #else - #error "The demo code can't be executed on this board." + static UnbufferedSerial modbus_serial(D14, D15); + DigitalOut modbus_dir(PTD6); + #endif #endif +int us_time_to_send_bit; static volatile BOOL RxEnable, TxEnable; // Cam - keep a static copy of the RxEnable and TxEnable // status for the simulated ISR (ticker) @@ -72,11 +77,11 @@ prvvUARTISR( void ) { if ( TxEnable ) - if(pc.writeable()) + if(modbus_serial.writeable()) prvvUARTTxReadyISR(); if ( RxEnable ) - if(pc.readable()) + if(modbus_serial.readable()) prvvUARTRxISR(); } @@ -96,7 +101,10 @@ BOOL xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity ) { - pc.baud(ulBaudRate); + modbus_dir=INPUT; + modbus_serial.baud(ulBaudRate); + modbus_serial.format(8,(SerialBase::Parity) eParity,1); + us_time_to_send_bit=1000000/(ulBaudRate); #if defined(DEF_RS485_PORT) // mbed serial port #if defined(TARGET_NUMAKER_PFM_NUC472) // for NUC472 board pc.set_rs485_mode(PF_11); @@ -118,8 +126,11 @@ /* Put a byte in the UARTs transmit buffer. This function is called * by the protocol stack if pxMBFrameCBTransmitterEmpty( ) has been * called. */ - //printf("[%02x]", ucByte ); - pc.putc( ucByte); + printf("[%02x]", ucByte ); + modbus_dir=OUTPUT; + modbus_serial.write( &ucByte,1); + wait_us(us_time_to_send_bit*11);//maximum 11 bits to send + modbus_dir=INPUT; return TRUE; } @@ -129,8 +140,9 @@ /* Return the byte in the UARTs receive buffer. This function is called * by the protocol stack after pxMBFrameCBByteReceived( ) has been called. */ - *pucByte = pc.getc(); - //printf("<%02x>", *pucByte ); + modbus_dir=INPUT; + modbus_serial.read(pucByte,1); + printf("<%02x>", *pucByte ); return TRUE; }