Commit 5e220408 authored by service-config's avatar service-config

Baud reduced to fix errors in transmission

parent fb0dba44
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
#include <bldc_interface_uart.h> #include <bldc_interface_uart.h>
// Settings // Settings
#define __CUA_UART_BAUDRATE 115200 // 9600 #define __CUA_UART_BAUDRATE 57600 // 57600 was tested to be the max value without errors //115200 // 9600
// Private functions // Private functions
static void send_packet(unsigned char *data, int len); static void send_packet(unsigned char *data, int len);
...@@ -58,30 +58,18 @@ void softwareSerialEvent() { ...@@ -58,30 +58,18 @@ void softwareSerialEvent() {
bool isWork = false; bool isWork = false;
#ifdef DEBUG_BLDC #ifdef DEBUG_BLDC
int len = 0; int len = 0;
//uint8_t rbyte;
#endif #endif
if(mySerial.available()) { if(mySerial.available()) {
//isWork = true;
#ifdef DEBUG_BLDC #ifdef DEBUG_BLDC
Serial.println(F("[ bldc ] softwareSerialEvent: Reading from serial...")); Serial.println(F("[ bldc ] softwareSerialEvent: Reading from serial..."));
#endif #endif
while (mySerial.available()) { while (mySerial.available()) {
bldc_interface_uart_process_byte(mySerial.read());
//#ifndef DEBUG_BLDC #ifdef DEBUG_BLDC
bldc_interface_uart_process_byte(mySerial.read());
#ifdef DEBUG_BLDC
len += sizeof(uint8_t);
#endif
/*#else
rbyte = mySerial.read();
bldc_interface_uart_process_byte(rbyte);
Serial.write(rbyte);
len += sizeof(uint8_t); len += sizeof(uint8_t);
#endif*/ #endif
//delay(2);
} }
...@@ -112,10 +100,7 @@ void softwareSerialEvent() { ...@@ -112,10 +100,7 @@ void softwareSerialEvent() {
* Data array length * Data array length
*/ */
void send_packet(unsigned char *data, int len) { void send_packet(unsigned char *data, int len) {
/*if (len > (PACKET_MAX_PL_LEN + 5)) {
return;
}*/
//data[0] = 4;
// Send the data over UART // Send the data over UART
#ifdef DEBUG_BLDC #ifdef DEBUG_BLDC
Serial.print(F("[ bldc ] send_packet = len[")); Serial.print(F("[ bldc ] send_packet = len["));
...@@ -123,21 +108,19 @@ void send_packet(unsigned char *data, int len) { ...@@ -123,21 +108,19 @@ void send_packet(unsigned char *data, int len) {
Serial.print(F("] write[")); Serial.print(F("] write["));
for (int i = 0; i < len ; i++){ for (int i = 0; i < len ; i++){
Serial.print(data[i]); Serial.print(data[i]);
Serial.print(F(":")); Serial.print(F(":"));
} }
//Serial.write(data, len);
Serial.println(F("]")); Serial.println(F("]"));
#endif #endif
mySerial.write(data, len); mySerial.write(data, len);
delay(1);
} }
void comm_uart_arduino_init() { void comm_uart_arduino_init() {
// Initialize UART // Initialize UART
mySerial.begin(__CUA_UART_BAUDRATE); mySerial.begin(__CUA_UART_BAUDRATE);
/*while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}*/
// Initialize the bldc interface and provide a send function // Initialize the bldc interface and provide a send function
bldc_interface_uart_init(&send_packet); bldc_interface_uart_init(&send_packet);
...@@ -172,11 +155,11 @@ void send_packet(unsigned char *data, int len) { ...@@ -172,11 +155,11 @@ void send_packet(unsigned char *data, int len) {
TIMSK1 |= (1 << OCIE1A);*/ TIMSK1 |= (1 << OCIE1A);*/
//set timer2 interrupt at 1kHz //set timer2 interrupt at 1kHz
TCCR2A = 0;// set entire TCCR2A register to 0 TCCR2A = 0; // set entire TCCR2A register to 0
TCCR2B = 0;// same for TCCR2B TCCR2B = 0; // same for TCCR2B
TCNT2 = 0;//initialize counter value to 0 TCNT2 = 0; //initialize counter value to 0
// set compare match register for 1khz increments // set compare match register for 1khz increments
OCR2A = 249;// = (16*10^6) / (8000*8) - 1 (must be <256) OCR2A = 249; // = (16*10^6) / (8000*8) - 1 (must be <256)
// turn on CTC mode // turn on CTC mode
TCCR2A |= (1 << WGM21); TCCR2A |= (1 << WGM21);
// Set CS21 bit for 64 prescaler // Set CS21 bit for 64 prescaler
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment