To receive GPS data, we'll use the Neo-6m GPS module. Like the HC-05 Bluetooth module from the previous part, it uses UART for communication. We'll use UART0 for this part of the project.
Table of Contents
- Requirements
- Flowchart
Implementation
- UART Configuration
- Connections
- Test
- Interrupt
- Final Code
Requirements
- 1 x Raspberry Pico board
- 1 x USB Cable type 2.0
- 9 x M-M jumper wires
- 1 x HC-05 Bluetooth Module
- 2 x Mini Breadboards
- Serial Bluetooth App
Flowchart
in the 'Command' part of the series.
// Configure gp0 as UART0 Tx Pin
// Connected to HC-05 Rx Pin
pads_bank0.gpio(0).modify(|_, w| w
.pue().set_bit()
.pde().set_bit()
.od().clear_bit()
.ie().set_bit()
);
io_bank0.gpio(0).gpio_ctrl().modify(|_, w| w.funcsel().uart());
// Configure gp1 as UART0 Rx Pin
// Will be connected to GPS Module Tx Pin
pads_bank0.gpio(1).modify(|_, w| w
.pue().set_bit()
.pde().set_bit()
.od().clear_bit()
.ie().set_bit()
);
io_bank0.gpio(1).gpio_ctrl().modify(|_, w| w.funcsel().uart());
Create a UART global variable and move uart into it.
static UARTDATA: Mutex<RefCell<Option<UART0>>> = Mutex::new(RefCell::new(None));
Import UART0
use rp2040_pac::UART0;
Move uart_data into its global variable.
cortex_m::interrupt::free(|cs| {
UARTDATA.borrow(cs).replace(Some(uart_data));
});
Connections
The electrical connections will be as shown below.
Interrupt
We first have to unmask the UART0 interrupt to enable it fully.
It is a good idea to have all the interrupts unmasked after we are through with all the peripherals set up. We can therefore move all the unmasking to the end of the set up.
// Unmask interrupts
unsafe {
cortex_m::peripheral::NVIC::unmask(Interrupt::TIMER_IRQ_0);
cortex_m::peripheral::NVIC::unmask(interrupt::UART0_IRQ);
cortex_m::peripheral::NVIC::unmask(interrupt::UART1_IRQ);
}
We need a buffer that will hold the data from the GPS module. It is a variable shared between main and interrupts. We'll put it as a global variable.
static BUFFER: Mutex<RefCell<Option<String<164>>>> = Mutex::new(RefCell::new(None));// buffer to hold received gps data
In the main thread under buffers we'll initialize our buffer and move it into global scope.
let gpsbuf = String::new();// buffer to hold gps data
cortex_m::interrupt::free(|cs| {
BUFFER.borrow(cs).replace(Some(gpsbuf));
});
A naive approach we can use to acquire a GPS NMEA sentence is to accumulate bytes until we encounter an end-of-line byte. We can then process the received sentences into latitudes and longitudes. The flowchart below helps visualize this process.
final copy.
Running this program will flash it into the Pico and we'll be set to receive GPS data.
Next we shall test our program by continuously receiving and viewing the GPS data.
SOCIAL SHARE CARD GENERATOR