@SB_LEE wrote:
Hi.
I’m currently using ofxserial add-on to communicate with arduino uno to high baud_rate
which is 2,000,000(2M).
Before I use ofx, I made my test example in processing 3.02 and It worked well.
When I run ofx version of this example at this baud rate however, I cannot get any response from arduino.
Rx led in arduino still blinks but Tx does not.
BUT when I run same example at baud rate 230400 or below, arduino sends me back values.I’m currently using OS X EL CAPITAN 10.11.5(15F34) and Xcode 7.3.1 (7D1014).
How can I use that baud rate (2M) in ofxserial?
Any help would be appreciated.Thanks !
OFX CODE
//--------------------------------------------------------------
void ofApp::setup(){ofBackground(0); std::vector<ofx::IO::SerialDeviceInfo> devicesInfo = ofx::IO::SerialDeviceUtils::listDevices(); ofLogNotice("ofApp::setup") << "Connected Devices: "; for (std::size_t i = 0; i < devicesInfo.size(); ++i) { ofLogNotice("ofApp::setup") << "\t" << devicesInfo[i]; } int baud = 2000000; if (!devicesInfo.empty()) { // Connect to the first matching device. bool success = device.setup(devicesInfo[0], baud); if(success) { ofLogNotice("ofApp::setup") << "Successfully setup " << devicesInfo[0]; ofLogNotice("ofApp::setup") << "BAUDRATE : " << device.getBauds(); ofLogNotice("ofApp::setup") << "Device Info : " << devicesInfo[0]; } else { ofLogNotice("ofApp::setup") << "Unable to setup " << devicesInfo[0]; } } else { ofLogNotice("ofApp::setup") << "No devices connected."; }
}
//--------------------------------------------------------------
void ofApp::update(){try { while (device.available() > 0) { sz = device.readByte(val1); receiveVal = val1; } device.writeByte(sendVal); sendVal++; if(sendVal > 255) { sendVal = 0; } } catch (const std::exception& exc) { ofLogError("ofApp::update") << exc.what(); }
}
//--------------------------------------------------------------
void ofApp::draw(){ofSetColor(255, 255, 255); ofDrawBitmapString("SIZE: " + ofToString(sz), 0, 220); ofDrawBitmapString("VAL : " + ofToString((int)val1), 0, 290); ofDrawBitmapString("ReceiveVal : " + ofToString(receiveVal), 0, 360);
}
ARDUINO CODE
volatile uint8_t data;
void setup()
{
UART_init();
}ISR (USART_RX_vect) {
data = UDR0;
UDR0 = data;
return;
}void loop()
{}
void UART_init() {
//*****************************UART initialisation*****************************//
UCSR0A |= (1 << U2X0); // Double up UART //
UCSR0B |= (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); // UART RX, TX enable //
// RX Interrupt enable //
UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); // Asynchrous 8N1 //
UBRR0H = 0; //
UBRR0L = 0; // Baud Rate 2 MBit //
//*****************************UART initialisation*****************************//
}
Posts: 1
Participants: 1