/* Software Uart For Stm32 By Liyanboy74 https://github.com/liyanboy74 */ #include #include #include #include #define Number_Of_SoftUarts 1 // Max 8 #define SoftUartTxBufferSize 32 #define SoftUartRxBufferSize 64 #define SoftUart_DATA_LEN 8 // Max 8 Bit #define SoftUart_PARITY 0 // 0=None 1=odd 2=even #define SoftUart_STOP_Bit 1 // Number of stop bits typedef enum { SoftUart_OK, SoftUart_Error } SoftUartState_E; typedef struct { uint8_t Tx[SoftUartTxBufferSize]; uint8_t Rx[SoftUartRxBufferSize]; } SoftUartBuffer_S; typedef struct { uint8_t TxNComplated; uint8_t TxEnable; uint8_t RxEnable; uint8_t TxBitShift, TxBitCounter; uint8_t RxBitShift, RxBitCounter; uint8_t TxIndex, TxSize; uint8_t RxIndex; SoftUartBuffer_S *Buffer; uint8_t RxTimingFlag; uint8_t RxBitOffset; uint8_t RxPinValue; // set before SoftUartHandler uint8_t TxPinValue; // get after SoftUartHandler } SoftUart_S; // Call Every (0.2)*(1/9600) = 20.83 uS void SoftUartHandler(void); void SoftUartWaitUntilTxComplate(); uint8_t SoftUartRxAlavailable(); SoftUartState_E SoftUartPuts(uint8_t *Data, uint8_t Len); SoftUartState_E SoftUartEnableRx(); SoftUartState_E SoftUartDisableRx(); SoftUart_S *SoftUartInit(); SoftUartState_E SoftUartReadRxBuffer(uint8_t *Buffer, uint8_t Len);