объект создается, begin проходит, write срабатывает, биты правильные, с таймингами беда. получение не пробовала
This commit is contained in:
1 parent
136fbc78d3
commit
7f0b704b05
2 files changed
+12
-16
No files matched your search
@@ -202,7 +202,7 @@ void SoftwareSerial::recv()
|
|||||||
|
|
||||||
uint8_t SoftwareSerial::rx_pin_read()
|
uint8_t SoftwareSerial::rx_pin_read()
|
||||||
{
|
{
|
||||||
return (uint8_t)HAL_GPIO_ReadPin((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receivePin);
|
return (uint8_t)HAL_GPIO_ReadPin((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receiveBitMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -236,8 +236,8 @@ SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inv
|
|||||||
_buffer_overflow(false),
|
_buffer_overflow(false),
|
||||||
_inverse_logic(inverse_logic)
|
_inverse_logic(inverse_logic)
|
||||||
{
|
{
|
||||||
setTX(transmitPin);
|
_transmitPin = transmitPin;
|
||||||
setRX(receivePin);
|
_receivePin = receivePin;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -250,12 +250,9 @@ SoftwareSerial::~SoftwareSerial()
|
|||||||
|
|
||||||
void SoftwareSerial::setTX(uint8_t tx)
|
void SoftwareSerial::setTX(uint8_t tx)
|
||||||
{
|
{
|
||||||
// First write, then set output. If we do this the other way around,
|
// First configure then write because writing pin didn't work until config is applied
|
||||||
// the pin would be output low for a short while before switching to
|
|
||||||
// output high. Now, it is input with pullup for a short while, which
|
|
||||||
// is fine. With inverse logic, either order is fine.
|
|
||||||
digitalWrite(tx, _inverse_logic ? LOW : HIGH); // todo проверить, что правда выставляется до конфигурации
|
|
||||||
pinMode(tx, OUTPUT);
|
pinMode(tx, OUTPUT);
|
||||||
|
digitalWrite(tx, _inverse_logic ? LOW : HIGH);
|
||||||
_transmitBitMask = (uint16_t)digitalPinToBitMask(tx); // save tx bit mask
|
_transmitBitMask = (uint16_t)digitalPinToBitMask(tx); // save tx bit mask
|
||||||
_transmitPortRegister = (uint32_t)digitalPinToPort(tx); // save tx port adress
|
_transmitPortRegister = (uint32_t)digitalPinToPort(tx); // save tx port adress
|
||||||
}
|
}
|
||||||
@@ -266,7 +263,6 @@ void SoftwareSerial::setRX(uint8_t rx)
|
|||||||
pinMode(rx, INPUT_PULLUP); // pullup for normal logic
|
pinMode(rx, INPUT_PULLUP); // pullup for normal logic
|
||||||
else
|
else
|
||||||
pinMode(rx, INPUT);
|
pinMode(rx, INPUT);
|
||||||
_receivePin = rx; // save rx digital pin number
|
|
||||||
_receiveBitMask = (uint16_t)digitalPinToBitMask(rx); // save rx bit mask
|
_receiveBitMask = (uint16_t)digitalPinToBitMask(rx); // save rx bit mask
|
||||||
_receivePortRegister = (uint32_t)digitalPinToPort(rx); // save rx port adress
|
_receivePortRegister = (uint32_t)digitalPinToPort(rx); // save rx port adress
|
||||||
}
|
}
|
||||||
@@ -284,6 +280,10 @@ uint16_t SoftwareSerial::subtract_cap(uint16_t num, uint16_t sub)
|
|||||||
//
|
//
|
||||||
void SoftwareSerial::begin(long speed)
|
void SoftwareSerial::begin(long speed)
|
||||||
{
|
{
|
||||||
|
// set pins config
|
||||||
|
setRX(_receivePin);
|
||||||
|
setTX(_transmitPin);
|
||||||
|
|
||||||
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
|
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
|
||||||
|
|
||||||
// limit speed
|
// limit speed
|
||||||
@@ -357,6 +357,8 @@ void SoftwareSerial::begin(long speed)
|
|||||||
|
|
||||||
tunedDelay(_tx_delay); // if we were low this establishes the end
|
tunedDelay(_tx_delay); // if we were low this establishes the end
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
ErrorMsgHandler("SoftwareSerial.begin(): Rx pin does not support interrupts, use different pin");
|
||||||
|
|
||||||
// #if _DEBUG
|
// #if _DEBUG
|
||||||
// pinMode(_DEBUG_PIN1, OUTPUT);
|
// pinMode(_DEBUG_PIN1, OUTPUT);
|
||||||
@@ -430,12 +432,9 @@ size_t SoftwareSerial::write(uint8_t byte)
|
|||||||
|
|
||||||
// Write the start bit
|
// Write the start bit
|
||||||
if (inv)
|
if (inv)
|
||||||
// todo проверить, можно ли так выставлять через адрес порта
|
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
||||||
// *reg |= reg_mask; // бит tx в 1
|
|
||||||
else
|
else
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
||||||
// *reg &= inv_mask; // бит tx в 0
|
|
||||||
|
|
||||||
tunedDelay(delay);
|
tunedDelay(delay);
|
||||||
|
|
||||||
@@ -443,10 +442,8 @@ size_t SoftwareSerial::write(uint8_t byte)
|
|||||||
for (uint8_t i = 8; i > 0; --i)
|
for (uint8_t i = 8; i > 0; --i)
|
||||||
{
|
{
|
||||||
if (byte & 1) // choose bit
|
if (byte & 1) // choose bit
|
||||||
// *reg |= reg_mask; // send 1
|
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
||||||
else
|
else
|
||||||
// *reg &= inv_mask; // send 0
|
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
||||||
|
|
||||||
tunedDelay(delay);
|
tunedDelay(delay);
|
||||||
@@ -456,10 +453,8 @@ size_t SoftwareSerial::write(uint8_t byte)
|
|||||||
// restore pin to natural state
|
// restore pin to natural state
|
||||||
if (inv)
|
if (inv)
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
||||||
// *reg &= inv_mask; // бит tx в 0
|
|
||||||
else
|
else
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
||||||
// *reg |= reg_mask; // бит tx в 1
|
|
||||||
|
|
||||||
interrupts(); // enable interrupts
|
interrupts(); // enable interrupts
|
||||||
tunedDelay(_tx_delay);
|
tunedDelay(_tx_delay);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ private:
|
|||||||
uint8_t _receivePin;
|
uint8_t _receivePin;
|
||||||
uint16_t _receiveBitMask;
|
uint16_t _receiveBitMask;
|
||||||
uint32_t _receivePortRegister;
|
uint32_t _receivePortRegister;
|
||||||
|
uint8_t _transmitPin;
|
||||||
uint16_t _transmitBitMask;
|
uint16_t _transmitBitMask;
|
||||||
uint32_t _transmitPortRegister;
|
uint32_t _transmitPortRegister;
|
||||||
uint8_t _int_maskMux;
|
uint8_t _int_maskMux;
|
||||||
|
|||||||
Reference in new issue
Block a user