mitchellclaxton wrote: ↑Wed Mar 13, 2019 1:21 am
OK so i went with UART 2 instead of UART 1 and i used SERIAL_8N1 because i'm using no parity.
I'm getting some readings back now but it's the same thing. 0, 28 over and over whenever i try to pass in a serial command.
Does this mean anything to you?
That does not mean anything to me.
Perhaps posting your code you are using for reading the serial port?
Here is the code I have to read the serial port on the ESP32:
In the declaration section, other code for other tasks and other declarations will be missing
Code: Select all
#define evtReceiveSerial_LIDAR ( 1 << 0 ) //1
TaskHandle_t xHandle_ReceiveSerial_LIDAR = NULL;
hw_timer_t * timer = NULL;
/* create event group */
EventGroupHandle_t eg;
SemaphoreHandle_t sema_ReceiveSerial_LIDAR;
#define TimerDivider 80
#define TaskCore1 1
#define TaskCore0 0
#define ReceiveSerialStackSize 20000
#define SerialDataBits 115200
HardwareSerial LIDARSerial ( 2 );
// pin 26=RX, pin 25=TX
String sSerial = "";
String sSerialSentence = "";
void IRAM_ATTR onTimer()
{
BaseType_t xHigherPriorityTaskWoken;
iTicCount++;
if ( (iTicCount % 2) == 0 )
{
if ( (xSemaphoreTakeFromISR(sema_ReceiveSerial_LIDAR, &xHigherPriorityTaskWoken)) == pdTRUE ) // grab semaphore, no wait
{
xEventGroupSetBitsFromISR(eg, evtReceiveSerial_LIDAR, &xHigherPriorityTaskWoken); // trigger every 2mS, if not already processing
}
}
if ( iTicCount == OneK )
{
iTicCount = 0;
}
} // void IRAM_ATTR onTimer()
Code in setup
Code: Select all
void setup()
{
LIDARSerial.begin ( SerialDataBits, SERIAL_8N1, 26, 25 );
eg = xEventGroupCreate();
timer = timerBegin( TIMER_FOUR, TimerDivider, true );
timerAttachInterrupt( timer, &onTimer, true );
///
/// ??? set call back to 500 for .5mS ?????
///
timerAlarmWrite(timer, OneK, true);
timerAlarmEnable(timer);
///////////////
xTaskCreatePinnedToCore ( fReceiveSerial_LIDAR, "fReceiveSerial_LIDAR", ReceiveSerialStackSize, NULL, Priority5, &xHandle_ReceiveSerial_LIDAR, TaskCore1 ); // assigned to core
sema_ReceiveSerial_LIDAR = xSemaphoreCreateMutex();
xSemaphoreGive ( sema_ReceiveSerial_LIDAR );
}
The code for the receive serial task:
Code: Select all
void fReceiveSerial_LIDAR( void * parameters )
{
bool BeginSentence = false;
sSerial.reserve ( StringBufferSize300 );
char OneChar;
for ( ;; )
{
EventBits_t xbit = xEventGroupWaitBits (eg, evtReceiveSerial_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY);
if ( LIDARSerial.available() >= 1 )
{
while ( LIDARSerial.available() )
{
OneChar = LIDARSerial.read();
if ( BeginSentence )
{
if ( OneChar == '>')
{
if ( xSemaphoreTake( sema_ParseLIDAR_ReceivedSerial, xSemaphoreTicksToWait10 ) == pdTRUE )
{
xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &sSerial );
xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
//
}
BeginSentence = false;
break;
}
sSerial.concat ( OneChar );
}
else
{
if ( OneChar == '<' )
{
sSerial = ""; // clear string buffer
BeginSentence = true; // found begining of sentence
}
}
} // while ( LIDARSerial.available() )
} //if ( LIDARSerial.available() >= 1 )
xSemaphoreGive( sema_ReceiveSerial_LIDAR );
}
vTaskDelete( NULL );
} //void fParseSerial( void * parameters )
I send sentences that begin with a "<" and end with a ">". If a "<" is not received no recording of received serial is done till a "<" is received. Recording is done. of incoming serial until the end of a sentence ">" is received. At which time the received serial is placed into a queue and sent to a serial parser. In this way the serial receiver can get back to work.