rossihwang / pico_dma_uart Goto Github PK
View Code? Open in Web Editor NEWraspberry pi pico dma uart example
raspberry pi pico dma uart example
Hello,
I'm using dma to read data from neo m8n gps module, it sends nmea sentences every 100 ms.
Since it's a lots of data roughly an uint8_t 400 element array.
So, I set up the dma and uart as following but I'm not able to read data more than 64 bytes. Only the ring buffer is creating problems here, if it's set to values more that 6 the the pico along with usb hangs. My keyboard and mouse also don't works or malfunctions😂.
//-----------------------------------------------------------------//
#include <string.h>
#include <pico/time.h>
#include <stdio.h>
#include "pico/stdlib.h"
#include <hardware/dma.h>
#include <hardware/uart.h>
#define gps_buf_max_expctd_len 64
uint32_t gps_raw_buff[gps_buf_max_expctd_len];
static void UART_setup(int baud){
uart_init(uart1, 2400);
gpio_set_function(8, GPIO_FUNC_UART);
gpio_set_function(9, GPIO_FUNC_UART);
int __unused actual = uart_set_baudrate(uart1, baud);
uart_set_hw_flow(uart1, false, false);
uart_set_format(uart1, 8, 1, UART_PARITY_NONE);
uart_set_fifo_enabled(uart1, false);
}
static void configure_dma() {
int chan = 0;//dma_claim_unused_channel(true);
dma_channel_config config = dma_channel_get_default_config(chan);
channel_config_set_transfer_data_size(&config, DMA_SIZE_8);
channel_config_set_read_increment(&config, false);
channel_config_set_write_increment(&config, true);
channel_config_set_ring(&config, true, 6);
channel_config_set_dreq(&config, uart_get_dreq(uart1, false));
dma_channel_configure(
chan,
&config,
gps_raw_buff,
&uart1_hw->dr,
UINT32_MAX,
true
);
}
int main() {
stdio_usb_init();
UART_setup(9600);
sleep_ms(100);
GPS_init();
configure_dma();
while(1){
sleep_ms(100);
printf("%.*s\n------------------------------\n", gps_buf_max_expctd_len, gps_raw_buff);
}
}
Note: uart and usb both enabled at CMakeLists.txt
Also gps data rate10Hz, and baud115200(including pico uart to 115200) was set using GPS_init();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.