Comments (2)
I have Serial working between the K210 and ESP32 using a custom class I wrote based on UARTClass:
(Please note, to update the ESP32 firmware, the reset button must be held down during flashing)
Maix_UART.h
#ifndef MAIX_UART_H
#define MAIX_UART_H
class UART
{
public:
UART(uint8_t rx = 6, uint8_t tx = 7,
fpioa_function_t rx_func = FUNC_UART1_RX,
fpioa_function_t tx_func = FUNC_UART1_TX,
uart_bitwidth_t width = UART_BITWIDTH_8BIT,
uart_stopbit_t stopbit = UART_STOP_1,
uart_parity_t parity = UART_PARITY_NONE)
{
this->rx = rx;
this->tx = tx;
this->rx_func = rx_func;
this->tx_func = tx_func;
this->width = width;
this->stopbit = stopbit;
this->parity = parity;
}
void begin(uint32_t baud = 115200)
{
this->baud = baud;
fpioa_set_function(rx, this->rx_func);
fpioa_set_function(tx, this->tx_func);
uart_init(this->handle);
uart_configure(this->handle, this->baud, this->width, this->stopbit, this->parity);
this->buffer = new RingBuffer();
uart_set_receive_trigger(this->handle, UART_RECEIVE_FIFO_1);
uart_irq_register(this->handle, UART_RECEIVE, this->receiveCB, this, 5);
sysctl_enable_irq();
}
static int receiveCB(void* ctx)
{
char tmp = '\0';
UART* uart = (UART*)ctx;
while(uart_receive_data(uart->handle, &tmp, 1)) { uart->buffer->store_char(tmp); }
return 0;
}
int available()
{
return this->buffer->available();
}
char read()
{
if(this->available()) { return this->buffer->read_char(); }
return -1;
}
void print(char* data, int len = -1)
{
if(len < 0) len = strlen(data);
for(int i = 0; i < len; ++i)
{
while(uart[this->handle]->LSR & (1u << 5)) { }
uart[this->handle]->THR = data[i];
}
}
void println(char* data, int len = -1)
{
char newline[] = "\n";
this->print(data, len);
this->print(newline, strlen(newline));
}
private:
uint32_t baud;
uint8_t rx;
uint8_t tx;
fpioa_function_t rx_func;
fpioa_function_t tx_func;
uart_bitwidth_t width;
uart_stopbit_t stopbit;
uart_parity_t parity;
uart_device_number_t handle;
RingBuffer* buffer;
};
#endif//MAIX_UART_H
K210_Usage.ino
UART ESP32; //ESP32(6, 7);
void setup()
{
ESP32.begin(115200);
int nBytes = 0;
char buffer[255] = "";
char message[] = "Hello ESP32";
while(1)
{
ESP32.println(message);
nBytes = ESP32.available();
if(nBytes > 0)
{
for(int i = 0; i < nBytes; ++i) { buffer[i] = (char)ESP32.read(); }
buffer[nBytes] = '\0';
Serial.println(buffer);
}
delay(1000);
}
}
void loop() { }
ESP32_Usage.ino
void setup()
{
Serial.begin(115200);
int nBytes = 0;
char buffer[255] = "";
char message[] = "Hello ESP32";
char response[] = "Hello K210";
while(1)
{
nBytes = Serial.available();
if(nBytes > 0)
{
for(int i = 0; i < nBytes; ++i) { buffer[i] = (char)Serial.read(); }
buffer[nBytes] = '\0';
Serial.print(buffer);
if(strncmp(buffer, message, strlen(message)) == 0) { Serial.println(response); }
}
delay(500);
}
}
void loop() { }
from maixduino.
For printing floats, the print() method above may need to be modified to use sprintf() using preprocessor macros. This will make it more like the Arduino standard printer.
from maixduino.
Related Issues (20)
- Need assistance adding support for the stickV
- Need help running OpenCV and Dlib
- Maixduino no longer connecting to Maixpy IDE HOT 2
- RE: Trying the Given Selfie Source/Maixduino Selfie Source! HOT 1
- Maix Amigo basic display red and blue swapped HOT 1
- Cannot install board definitions - wrong link and wrong SHA256 HOT 3
- no serial connection HOT 7
- [TCP/İP Socket] live stream using maixduino as client HOT 3
- Maixduino Operating system HOT 3
- [UART] Maixduino Reading Serial port HOT 2
- How to display rtsp stream in maiduino board
- Is there any way to send images from a computer to maixduino board using micropython
- board missing HOT 1
- How to use C/C++ PlatformIO/Arduino Framework (Not MaixPy) to use wifi HOT 3
- Are There Plans for Maix M1s Support? HOT 1
- Is This Project Dead? HOT 1
- using "SD.h" library for SD card on maixduino HOT 1
- arg "channel_mask" in "i2s_init" function HOT 1
- use external I2S mems mic for Maix_Speech_Recognition HOT 1
- Where is your binocular example? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from maixduino.