11#if defined(ARDUINO_ARCH_STM32)
28 DEBUG_PRINT(1,
"wrong state 0x%02X", this->
state);
39 while (this->
pSerial->available())
43 #if defined(USART_CR2_LINEN)
44 this->
huart->Instance->ICR = USART_ICR_LBDCF;
51 #if defined(USART_CR2_LINEN)
52 this->
huart->Instance->RQR |= USART_RQR_SBKRQ;
58 this->
huart->Instance->BRR = this->
brr * 2;
60 this->
pSerial->write((
int) 0x00);
87 DEBUG_PRINT(1,
"wrong state 0x%02X", this->
state);
103 #if defined(USART_CR2_LINEN)
108 this->
huart->Instance->BRR = this->
brr;
126 DEBUG_PRINT(1,
"Rx timeout");
158 DEBUG_PRINT(1,
"wrong state 0x%02X", this->
state);
172 if (this->
pSerial->available() >= this->lenRx-1)
195 DEBUG_PRINT(1,
"Rx timeout");
232 this->
huart = Interface.getHandle();
259 #if defined(LIN_MASTER_LIN_PORT_TIMEOUT) && (LIN_MASTER_LIN_PORT_TIMEOUT > 0)
260 uint32_t startMillis = millis();
261 while ((!(*(this->
pSerial))) && (millis() - startMillis < LIN_MASTER_LIN_PORT_TIMEOUT));
267 #if defined(USART_CR2_LINEN)
268 this->
huart->Instance->CR1 &= ~USART_CR1_UE;
269 this->
huart->Instance->CR2 |= USART_CR2_LINEN;
270 this->
huart->Instance->CR1 |= USART_CR1_UE;
274 this->
brr = this->
huart->Instance->BRR;
278 DEBUG_PRINT(2,
"ok");
297 this->
huart->Instance->CR1 &= ~USART_CR1_UE;
298 this->
huart->Instance->CR2 &= ~USART_CR2_LINEN;
299 this->
huart->Instance->CR1 |= USART_CR1_UE;
LIN master emulation library using a HardwareSerial interface of STM32.
LIN master node base class.
uint8_t lenRx
receive buffer length (max. 12)
virtual void begin(uint16_t Baudrate=19200)
Open serial interface.
uint16_t baudrate
communication baudrate [Baud]
@ SLAVE_RESPONSE
LIN slave response frame.
uint8_t bufTx[12]
send buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
LIN_Master_Base::error_t _checkFrame(void)
Check received LIN frame.
LIN_Master_Base::error_t error
error state. Is latched until cleared
void _enableTransmitter(void)
Enable RS485 transmitter (DE=high)
uint32_t timeStart
starting time [us] for frame timeout
uint8_t lenTx
send buffer length (max. 12)
LIN_Master_Base::state_t state
status of LIN state machine
void _disableTransmitter(void)
Disable RS485 transmitter (DE=low)
error_t
LIN error codes. Use bitmasks, as error is latched. Use same as LIN_slave_portable.
@ ERROR_STATE
error in LIN state machine
@ ERROR_TIMEOUT
frame timeout error
state_t
state of LIN master state machine. Use bitmasks for fast checking multiple states
@ STATE_BODY
rest of frame is being sent/received
@ STATE_BREAK
sync break is being transmitted
@ STATE_IDLE
no LIN transmission ongoing
@ STATE_DONE
frame completed
virtual void end(void)
Close serial interface.
uint8_t bufRx[12]
receive buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
LIN_Master_Base::frame_t type
LIN frame type.
uint32_t timeoutFrame
max. frame duration [us]
uint32_t pinTx
pin used for transmit
UART_HandleTypeDef * huart
pointer to underlying HAL UART handle
void end(void)
Close serial interface.
LIN_Master_HardwareSerial_STM32(HardwareSerial &Interface, uint32_t PinRx, uint32_t PinTx, const char NameLIN[]="Master", const int8_t PinTxEN=INT8_MIN)
Class constructor.
LIN_Master_Base::state_t _sendBreak(void)
Send LIN break.
void begin(uint16_t Baudrate=19200)
Open serial interface.
LIN_Master_Base::state_t _receiveFrame(void)
Read and check LIN frame.
LIN_Master_Base::state_t _sendFrame(void)
Send LIN bytes (request frame: SYNC+ID+DATA[]+CHK; response frame: SYNC+ID)
HardwareSerial * pSerial
serial interface used for LIN
uint32_t pinRx
pin used for receive
uint32_t brr
BRR value if LIN mode is not available.