You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have following code from the serial example. I am using UART1 on stm32f401 with pins PA9 and PA10. Baudraet is 9600, I have a bluetooth module HC-05 connected.
Rx<->Tx PA9
Tx<->Rx PA10
I connect bluetooth module to my phone and use an app to send and read data, but I do not recieve it and cant read it back as well.
Anyone who can help me with it?
#![no_main]#![no_std]use panic_halt as _;use stm32f4xx_hal as hal;usecrate::hal::{block, pac, prelude::*, serial::config::Config};use cortex_m_rt::entry;use core::fmt::Write;#[entry]fnmain() -> ! {let dp = pac::Peripherals::take().unwrap();let cp = cortex_m::peripheral::Peripherals::take().unwrap();let gpioa = dp.GPIOA.split();//let gpiob = dp.GPIOB.split();letmut led = gpioa.pa5.into_push_pull_output();let rcc = dp.RCC.constrain();let clocks = rcc.cfgr.use_hse(8.MHz()).freeze();letmut delay = cp.SYST.delay(&clocks);// define RX/TX pinslet tx_pin = gpioa.pa9.into_alternate();let rx_pin = gpioa.pa10.into_alternate();// configure seriallet serial = dp
.USART1.serial((tx_pin, rx_pin),Config::default().baudrate(9600.bps()),&clocks,).unwrap();let(mut tx,mut rx) = serial.split();loop{// Receive what we just sentlet received:u16 = rx.read().unwrap();// Update LEDs to display what was receivedif received == 1{
led.set_high();}else{
led.set_low();}
tx.write(received).unwrap();
delay.delay_ms(10);}}
The text was updated successfully, but these errors were encountered:
I have fixed the Rx and changed configuration to read u16. I have also added block!(rx.read()).unwrap() and block!(tx.write(received).unwrap() .
I am able to receive the what I send from the phone. But the Tx is not working, its not transmitted back.
`//! Blinks an LED
#![no_main]
#![no_std]
use panic_halt as _;
use stm32f4xx_hal as hal;
use crate::hal::{block, pac, prelude::*, serial::config::Config};
use cortex_m_rt::entry;
use core::fmt::Write;
use core::ops::Range;
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::peripheral::Peripherals::take().unwrap();
let gpioa = dp.GPIOA.split();
//let gpiob = dp.GPIOB.split();
let mut led = gpioa.pa5.into_push_pull_output();
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.use_hse(8.MHz()).freeze();
let mut delay = cp.SYST.delay(&clocks);
// define RX/TX pins
//let tx_pin = gpiob.pb6.into_alternate();
//let rx_pin = gpiob.pb7.into_alternate();
let tx_pin = gpioa.pa9.into_alternate();
let rx_pin = gpioa.pa10.into_alternate();
let serial = dp
.USART1
.serial(
(tx_pin, rx_pin),
Config::default().baudrate(9600.bps()),
&clocks,
)
.unwrap()
// Make this Serial object use u16s instead of u8s
.with_u16_data();
let (mut tx, mut rx) = serial.split();
loop {
// Read character and echo it back
let received: u16 = block!(rx.read()).unwrap();
if received == 70 {
led.set_high();
} else {
led.set_low();
}
block!(tx.write(received)).unwrap();
delay.delay_ms(10);
}
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I have following code from the serial example. I am using UART1 on stm32f401 with pins PA9 and PA10. Baudraet is 9600, I have a bluetooth module HC-05 connected.
Rx<->Tx PA9
Tx<->Rx PA10
I connect bluetooth module to my phone and use an app to send and read data, but I do not recieve it and cant read it back as well.
Anyone who can help me with it?
The text was updated successfully, but these errors were encountered: