Last active
February 17, 2019 12:08
-
-
Save djmcgill/d9e675fec5ce41fd96bc7d3fa488052b to your computer and use it in GitHub Desktop.
Adding a second serial UART
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[entry] | |
fn main() -> ! { | |
let mut peripherals = Peripherals::take().unwrap(); | |
let mut core = CorePeripherals::take().unwrap(); | |
let mut clocks = GenericClockController::with_internal_32kosc( | |
peripherals.GCLK, | |
&mut peripherals.PM, | |
&mut peripherals.SYSCTRL, | |
&mut peripherals.NVMCTRL, | |
); | |
let mut pins = arduino_mkrzero::Pins::new(peripherals.PORT); | |
let gclk0 = clocks.gclk0().clone(); | |
let rx_pin = pins.rx.into_pull_down_input(&mut pins.port).into_pad(&mut pins.port); | |
let tx_pin = pins.tx.into_push_pull_output(&mut pins.port).into_pad(&mut pins.port); | |
let mut serial = UART5::new( | |
&clocks.sercom5_core(&gclk0).unwrap(), | |
9600.hz(), | |
peripherals.SERCOM5, | |
&mut core.NVIC, | |
&mut peripherals.PM, | |
UART5Pinout::Rx3Tx2 {rx: rx_pin, tx: tx_pin}, | |
); | |
serial.write_str("Initialised\n").unwrap(); | |
let gclk1 = clocks.gclk1().clone(); // Tried gclk0 and gclk1 here | |
let gps_rx_pin: sercom::Sercom0Pad1 = pins.scl.into_pull_down_input(&mut pins.port).into_pad(&mut pins.port); | |
let gps_tx_pin: sercom::Sercom0Pad0 = pins.sda.into_push_pull_output(&mut pins.port).into_pad(&mut pins.port); | |
// Commenting out the below block makes it work every time | |
let mut gps_serial = sercom::UART0::new( | |
&clocks.sercom0_core(&gclk1).unwrap(), | |
9600.hz(), | |
peripherals.SERCOM0, | |
&mut core.NVIC, | |
&mut peripherals.PM, | |
sercom::UART0Pinout::Rx1Tx0 { | |
rx: gps_rx_pin, | |
tx: gps_tx_pin, | |
}, | |
); | |
// Sometimes passs this line, mostly it's just partially output i.e. "GPS I" before halting. | |
serial.write_str("GPS Initialised\n").unwrap(); | |
serial.write_str("\n").unwrap(); | |
loop {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment