Hello everyone,
I’m a beginner in Rust and currently working with the DFPlayer on my Nucleo64 board. I’ve gone through the C++ libraries of "DfPlayerRobot" on GitHub and reviewed the DFPlayer's datasheet completely. My goal is to simply play a single file on the SD card.
I’ve written a this rust code to initialize the DFPlayer, select the TF card, and use the default volume settings ( 30 ) . I’m sending the command to play the first song using USART for communication, and I’ve enabled the acknowledge bit in the command. However, the acknowledgment I’m receiving is: [7E, FF, 06, 40, 00, 00, 04, FE, B7, EF]
.
I’m not sure what’s going wrong since the music isn’t playing. The same acknowledgment code keeps appearing every time. Could anyone point out what might be causing this issue? Thank you so so much for the help <33
#![no_std]
#![no_main]
use defmt::*;
use embassy_stm32::usart::{Config, StopBits, Uart};
use embassy_stm32::{bind_interrupts, peripherals, usart};
use embassy_time::Timer;
use embassy_time::*;
use embassy_executor::Spawner;
use embedded_io::Write;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
USART1 => usart::InterruptHandler<peripherals::USART1>;
});
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
let mut config = Config::default();
config.baudrate=9600;
config.parity=usart::Parity::ParityNone;
// Initialization of UART on USART1
let mut uart: Uart<'_, embassy_stm32::mode::Async> = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH2, p.DMA1_CH1, config).unwrap();
let (mut tx, mut rx) = uart.split();
let mut ack_buffer = [0u8; 10];
let mut ack_buffer1 = [0u8; 10];
let mut ack_buffer2 = [0u8; 10];
// TF card initialize , enabling acknowledge command
let mut command_initialize: [u8; 10] = [ 0x7E, 0xFF, 0x06, 0x3F, 0x01, 0x00, 0x02, 0xFF, 0xA8, 0xEF ];
match tx.write(&command_initialize).await {
Ok(()) => {
info!("Initialization has written");
}
Err((e)) => {
info!("ZZZZ");
}
}
match rx.blocking_read(&mut ack_buffer) {
Ok(()) => {
//info!("Received {} bytes", n);
info!("ACK Response: {:X}", &ack_buffer);
}
Err(e) => {
info!("Error reading ACK: {:?}", e);
}
}
Timer::after_millis(4000).await;
// Playing the first song , enabling acknowledge command
let command_config1: [u8; 10] = [ 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xFF, 0xE6, 0xEF ];
match tx.write(&command_config1).await {
Ok(()) => {
info!("It has written ");
}
Err((e)) => {
info!("ZZZZ");
}
}
match rx.blocking_read(&mut ack_buffer1) {
Ok(()) => {
//info!("Received {} bytes", n);
info!("ACK Response: {:X}", &ack_buffer1);
}
Err(e) => {
info!("Error reading ACK: {:?}", e);
}
}
Timer::after_millis(1000).await;
}