BASIC4MCU | 질문게시판 | atmega128 - dfplayer 음원재생 오류 질문! 드립니다
페이지 정보
작성자 밍밍셜 작성일2023-11-18 23:01 조회1,551회 댓글1건본문
해당 코드와 회로도 납땜 후 실행중인데 됐다 안됐다를 반복하는데 이유가 코드 문제인건지 회로도 구성이나 모듈 자체가 문제인건지 잘 모르겠어요,, 참고로 df플레이어 모듈 본체에 다른 분들은 빨간 불이 들어오던데 첨부터 배송이 불 안들어오는 상태로 왔습니다ㅠㅠㅠ 코드와 회로도 첨부해요,,,ㅠㅠ
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
typedef unsigned char INT8;
typedef unsigned int INT16;
#define BAUD 9600
#define U2X_S 2 // Set of U2X --> 1 or 2
#define MYUBRR ((F_CPU*U2X_S)/(16L*BAUD)-1)
#define sbi(reg,bit) reg |= (1<<(bit)) // Set "bit"th bit of Register "reg"
#define cbi(reg,bit) reg &= ~(1<<(bit))
//
#define MP3_NEXT 0x01
#define MP3_PREVIOUS 0x02
#define MP3_TRAKING_NUM 0x03 // 0..2999
#define MP3_INC_VOLUME 0x04
#define MP3_DEC_VOLUME 0x05
#define MP3_VOLUME 0x06 // 0..30
#define MP3_EQ 0x07 // 0-Normal / 1-Pop / 2-Rock / 3-Jazz / 4-Classic / 5-Base
#define MP3_PLAYBACK_MODE 0x08 // 0-Repeat / 1-folder repeat / 2-single repeat / 3-random
#define MP3_PLAYBACK_SOURCE 0x09 // 0-U / 1-TF / 2-AUX / 3-SLEEP / 4-FLASH
#define MP3_STANDBY 0x0A
#define MP3_NORMAL_WORK 0x0B
#define MP3_RESET 0x0C
#define MP3_PLAYBACK 0x0D
#define MP3_PAUSE 0x0E
#define MP3_PLAY_FOLDER_FILE 0x0F // 0..10
#define MP3_VOLUME_ADJUST 0x10
#define MP3_REPEAT 0x11 // 0-stop play / 1-start repeat play
// Query the System Parameters
#define MP3_Q_STAY1 0x3C
#define MP3_Q_STAY2 0x3D
#define MP3_Q_STAY3 0x3E
#define MP3_Q_SEND_PRM 0x3F
#define MP3_Q_ERROR 0x40
#define MP3_Q_REPLY 0x41
#define MP3_Q_STATUS 0x42
#define MP3_Q_VALUE 0x43
#define MP3_Q_EQ 0x44
#define MP3_Q_PLAYBACK_MODE 0x45
#define MP3_Q_SOFT_VERSION 0x46
#define MP3_Q_TF_CARD_FILES 0x47
#define MP3_Q_U_DISK_CARD_FILES 0x48
#define MP3_Q_FLASH_CARD_FILES 0x49
#define MP3_Q_KEEPON 0x4A
#define MP3_Q_CURRENT_TRACK_TF 0x4B
#define MP3_Q_CURRENT_TRACK_U_DISK 0x4C
#define MP3_Q_CURRENT_TRACK_FLASH 0x4D
////////////////////////////////////////////////////////////////////////////////
//Commands parameters
////////////////////////////////////////////////////////////////////////////////
#define MP3_EQ_Normal 0
#define MP3_EQ_Pop 1
#define MP3_EQ_Rock 2
#define MP3_EQ_Jazz 3
#define MP3_EQ_Classic 4
#define MP3_EQ_Base 5
#define MP3_PLAYBACK_MODE_Repeat 0
#define MP3_PLAYBACK_MODE_folder_repeat 1
#define MP3_PLAYBACK_MODE_single_repeat 2
#define MP3_PLAYBACK_MODE_random 3
#define MP3_PLAYBACK_SOURCE_U 0
#define MP3_PLAYBACK_SOURCE_TF 1
#define MP3_PLAYBACK_SOURCE_AUX 2
#define MP3_PLAYBACK_SOURCE_SLEEP 3
#define MP3_PLAYBACK_SOURCE_FLASH 4
INT8 default_buffer[10] = {0x7E, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF}; // Default Buffer
volatile INT8 mp3_cmd_buf[10] = {0x7E, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF};
void USART0_Init( INT16 ubrr )
{
// Set baud rate
UBRR0H = (INT8)(ubrr>>8);
UBRR0L = (INT8)ubrr;
// Enable U2X
if(U2X_S == 2)
sbi(UCSR0A, U2X);
else
cbi(UCSR0A, U2X);
// Enable receiver and transmitter
sbi(UCSR0B, RXEN);
sbi(UCSR0B, TXEN);
// Set frame format: 8data, 1stop bit
cbi(UCSR0C, UMSEL); // asynch
cbi(UCSR0C, USBS); // 1 Stop bit
cbi(UCSR0C, UPM01); // No parity
cbi(UCSR0C, UPM00);
cbi(UCSR0B, UCSZ02); // 8-bit
sbi(UCSR0C, UCSZ01);
sbi(UCSR0C, UCSZ00);
}
void USART0_Transmit( char data )
{
// Wait for empty transmit buffer
while ( !( UCSR0A & 0x20 ) ) // (1<<UDRE)
;
// Put data into buffer, sends the data
UDR0 = data;
}
INT16 MP3_checksum (void)
{
INT16 sum = 0;
INT8 i;
for (i=1; i<7; i++) {
sum += mp3_cmd_buf[i];
}
return -sum;
}
void MP3_send_cmd (INT8 cmd, INT16 high_arg, INT16 low_arg)
{
INT8 i;
INT16 checksum;
mp3_cmd_buf[3] = cmd;
mp3_cmd_buf[5] = high_arg;
mp3_cmd_buf[6] = low_arg;
checksum = MP3_checksum();
mp3_cmd_buf[7] = (INT8) ((checksum >> 8) & 0x00FF);
mp3_cmd_buf[8] = (INT16) (checksum & 0x00FF);
for( i=0; i< 10; i++){
USART0_Transmit(mp3_cmd_buf[i]);
//putchar(mp3_cmd_buf[i]);
mp3_cmd_buf[i] = default_buffer[i];
}
}
void dfplayer_init(void)
{
MP3_send_cmd(MP3_PLAYBACK_SOURCE,0,MP3_PLAYBACK_SOURCE_TF);_delay_ms(10);
MP3_send_cmd(MP3_VOLUME, 0, 30); _delay_ms(10);
}
int main(void)
{
USART0_Init(MYUBRR); // 9600/8/n/1/n
dfplayer_init();
while(1)
{
MP3_send_cmd(0x12,0,1); _delay_ms(5000); // 0001.mp3 Play
}
}
댓글 1
조회수 1,551master님의 댓글
master 작성일
128은 UART0이 ISP에 연결되어 있습니다.
동작 할 때는 ISP 커넥터를 빼고 할 수도 있지만
ISP 할 때마다 mp3를 빼야 하는데 번거롭겠죠
1K옴 저항을 사용해서 PE0----1K옴----TX(MP3) 이렇게 연결 해두면 ISP를 계속 연결 해둬도 문제가 생기지 않습니다.
아니면 UART1을 사용해서 MP3에 연결하는 방법도 있겠죠