@@ -40,7 +40,8 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode)
|
||||
USART_DeInit(TELEMETRY_USART);
|
||||
return;
|
||||
}
|
||||
|
||||
//deinit inverted mode
|
||||
telemetryPortInvertedInit(0);
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TELEMETRY_DMA_TX_Stream_IRQ;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
@@ -87,11 +88,10 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode)
|
||||
// soft serial vars
|
||||
static uint8_t rxBitCount;
|
||||
static uint8_t rxByte;
|
||||
// single bit length expresses in half us
|
||||
static uint16_t bitLength;
|
||||
static uint16_t probeTimeFromStartBit;
|
||||
|
||||
//TODO:
|
||||
// - only 57600 supported for now
|
||||
// - handle other bitrates as well?
|
||||
//
|
||||
void telemetryPortInvertedInit(uint32_t baudrate)
|
||||
{
|
||||
if (baudrate == 0) {
|
||||
@@ -116,6 +116,20 @@ void telemetryPortInvertedInit(uint32_t baudrate)
|
||||
|
||||
rxBitCount = 0;
|
||||
|
||||
switch(baudrate) {
|
||||
case 115200:
|
||||
bitLength = 17;
|
||||
probeTimeFromStartBit = 25;
|
||||
break;
|
||||
case 57600:
|
||||
bitLength = 35; //34 was used before - I prefer to use use 35 because of lower error
|
||||
probeTimeFromStartBit = 52; //round down - 48 used in original implementation
|
||||
break;
|
||||
default:
|
||||
bitLength = 2000000/baudrate; //because of 0,5 us tick
|
||||
probeTimeFromStartBit = 3000000/baudrate;
|
||||
}
|
||||
|
||||
// configure bit sample timer
|
||||
TELEMETRY_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1; // 0.5uS
|
||||
TELEMETRY_TIMER->CCER = 0;
|
||||
@@ -162,7 +176,7 @@ void telemetryPortInvertedRxBit()
|
||||
{
|
||||
if (rxBitCount < 8) {
|
||||
if (rxBitCount == 0) {
|
||||
TELEMETRY_TIMER->ARR = 34;
|
||||
TELEMETRY_TIMER->ARR = bitLength;
|
||||
rxByte = 0;
|
||||
}
|
||||
else {
|
||||
@@ -333,7 +347,7 @@ void check_telemetry_exti()
|
||||
|
||||
if (rxBitCount == 0) {
|
||||
|
||||
TELEMETRY_TIMER->ARR = 48; // 1,5 cycle from start at 57600bps
|
||||
TELEMETRY_TIMER->ARR = probeTimeFromStartBit; // 1,5 cycle from start at 57600bps
|
||||
TELEMETRY_TIMER->CR1 |= TIM_CR1_CEN;
|
||||
|
||||
// disable start bit interrupt
|
||||
|
||||
Reference in New Issue
Block a user