Hi,
I am trying to use SOMO-II in a project using ATxmega128A1 (Microchip-Atmel).
The compiler used is the CodeVisionAVR V3.33 standard Ansi C.
I tested the SOMO-II in the key mode to assure that the micro-SD was OK and it play well.
The micro-SD is Kingston 2GB FAT16 and there are tracks named 001.mp3,002.mp3,... in a folder 01.
Below there are chunks of the program for Somo-II in serial mode.
Somo-II do not work in serial mode with this program. The led never light. I do not know what I am doing wrong.
Any help and suggestions are welcome. Thank you!
//___________________________________ usarts_init.h ___________________________________________________________________
#ifndef _USARTS_INIT_INCLUDED_
#define _USARTS_INIT_INCLUDED_
// USARTC0 is used as the default input device by the 'getchar' function
// #define _ALTERNATE_GETCHAR_ is inserted for this purpose
// in the main program source file before #include <stdio.h>
char getchar(void);
// USARTC0 is used as the default output device by the 'putchar' function
// #define _ALTERNATE_PUTCHAR_ is inserted for this purpose
// in the main program source file before #include <stdio.h>
void putchar(char c);
// USARTC0 initialization
void usartc0_init(void);
#endif
//____________________________________ usarts_init.c __________________________________________________________________
// I/O Registers definitions
#include <xmega128a1.h>
// USARTs initialization functions
#include "usarts_init.h"
// USARTC0 initialization
void usartc0_init(void)
{
// Note: The correct PORTC direction for the RxD, TxD and XCK signals
// is configured in the ports_init function.
// Transmitter is enabled
// Set TxD=1
PORTC.OUTSET=0x08;
// Communication mode: Asynchronous USART
// Data bits: 8
// Stop bits: 1
// Parity: Disabled
USARTC0.CTRLC=USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc;
// Receive complete interrupt: Disabled
// Transmit complete interrupt: Disabled
// Data register empty interrupt: Disabled
USARTC0.CTRLA=(USARTC0.CTRLA & (~(USART_RXCINTLVL_gm | USART_TXCINTLVL_gm | USART_DREINTLVL_gm))) |
USART_RXCINTLVL_OFF_gc | USART_TXCINTLVL_OFF_gc | USART_DREINTLVL_OFF_gc;
// Required Baud rate: 9600
// Real Baud Rate: 9601,0 (x1 Mode), Error: 0,0 %
USARTC0.BAUDCTRLA=0xF5;
USARTC0.BAUDCTRLB=((0x0C << USART_BSCALE_gp) & USART_BSCALE_gm) | 0x0C;
// Receiver: On
// Transmitter: On
// Double transmission speed mode: Off
// Multi-processor communication mode: Off
USARTC0.CTRLB=(USARTC0.CTRLB & (~(USART_RXEN_bm | USART_TXEN_bm | USART_CLK2X_bm | USART_MPCM_bm | USART_TXB8_bm))) |
USART_RXEN_bm | USART_TXEN_bm;
}
// Receive a character from USARTC0
// USARTC0 is used as the default input device by the 'getchar' function
// #define _ALTERNATE_GETCHAR_ is inserted for this purpose
// in the main program source file before #include <stdio.h>
#pragma used+
char getchar(void)
{
char data;
unsigned char status;
while (1)
{
while (((status=USARTC0.STATUS) & USART_RXCIF_bm) == 0);
data=USARTC0.DATA;
if ((status & (USART_FERR_bm | USART_PERR_bm | USART_BUFOVF_bm)) == 0) return data;
}
}
#pragma used-
// Write a character to the USARTC0 Transmitter
// USARTC0 is used as the default output device by the 'putchar' function
// #define _ALTERNATE_PUTCHAR_ is inserted for this purpose
// in the main program source file before #include <stdio.h>
#pragma used+
void putchar(char c)
{
while ((USARTC0.STATUS & USART_DREIF_bm) == 0);
USARTC0.DATA=c;
}
#pragma used-
//____________________________________________________________________________________________________ _________________
.
.
.
void somo_cmd(unsigned char cmd,unsigned char feedback,unsigned char para1,unsigned char para2);
.
.
.
somo_cmd(0x0F,0x00,0x01,0x01); // Play specifing folder (01) and track (01)
.
.
.
//____________________________________________________________________________________________________ _________________
void somo_cmd(unsigned char cmd,unsigned char feedback,unsigned char para1,unsigned char para2)
{
unsigned int chk;
unsigned char chk1;
unsigned char chk2;
chk = 0xFFFF - ((unsigned int)cmd + (unsigned int)feedback + (unsigned int)para1 + (unsigned int)para2) + 0x0001;
chk1 = (unsigned char)(chk >> 8);
chk2 = (unsigned char)chk;
putchar(0x7E);
putchar(cmd);
putchar(feedback);
putchar(para1);
putchar(para2);
putchar(chk1);
putchar(chk2);
putchar(0xEF);
delay_ms(100);
}
//____________________________________________________________________________________________________ _________________
I am trying to use SOMO-II in a project using ATxmega128A1 (Microchip-Atmel).
The compiler used is the CodeVisionAVR V3.33 standard Ansi C.
I tested the SOMO-II in the key mode to assure that the micro-SD was OK and it play well.
The micro-SD is Kingston 2GB FAT16 and there are tracks named 001.mp3,002.mp3,... in a folder 01.
Below there are chunks of the program for Somo-II in serial mode.
Somo-II do not work in serial mode with this program. The led never light. I do not know what I am doing wrong.
Any help and suggestions are welcome. Thank you!
//___________________________________ usarts_init.h ___________________________________________________________________
#ifndef _USARTS_INIT_INCLUDED_
#define _USARTS_INIT_INCLUDED_
// USARTC0 is used as the default input device by the 'getchar' function
// #define _ALTERNATE_GETCHAR_ is inserted for this purpose
// in the main program source file before #include <stdio.h>
char getchar(void);
// USARTC0 is used as the default output device by the 'putchar' function
// #define _ALTERNATE_PUTCHAR_ is inserted for this purpose
// in the main program source file before #include <stdio.h>
void putchar(char c);
// USARTC0 initialization
void usartc0_init(void);
#endif
//____________________________________ usarts_init.c __________________________________________________________________
// I/O Registers definitions
#include <xmega128a1.h>
// USARTs initialization functions
#include "usarts_init.h"
// USARTC0 initialization
void usartc0_init(void)
{
// Note: The correct PORTC direction for the RxD, TxD and XCK signals
// is configured in the ports_init function.
// Transmitter is enabled
// Set TxD=1
PORTC.OUTSET=0x08;
// Communication mode: Asynchronous USART
// Data bits: 8
// Stop bits: 1
// Parity: Disabled
USARTC0.CTRLC=USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc;
// Receive complete interrupt: Disabled
// Transmit complete interrupt: Disabled
// Data register empty interrupt: Disabled
USARTC0.CTRLA=(USARTC0.CTRLA & (~(USART_RXCINTLVL_gm | USART_TXCINTLVL_gm | USART_DREINTLVL_gm))) |
USART_RXCINTLVL_OFF_gc | USART_TXCINTLVL_OFF_gc | USART_DREINTLVL_OFF_gc;
// Required Baud rate: 9600
// Real Baud Rate: 9601,0 (x1 Mode), Error: 0,0 %
USARTC0.BAUDCTRLA=0xF5;
USARTC0.BAUDCTRLB=((0x0C << USART_BSCALE_gp) & USART_BSCALE_gm) | 0x0C;
// Receiver: On
// Transmitter: On
// Double transmission speed mode: Off
// Multi-processor communication mode: Off
USARTC0.CTRLB=(USARTC0.CTRLB & (~(USART_RXEN_bm | USART_TXEN_bm | USART_CLK2X_bm | USART_MPCM_bm | USART_TXB8_bm))) |
USART_RXEN_bm | USART_TXEN_bm;
}
// Receive a character from USARTC0
// USARTC0 is used as the default input device by the 'getchar' function
// #define _ALTERNATE_GETCHAR_ is inserted for this purpose
// in the main program source file before #include <stdio.h>
#pragma used+
char getchar(void)
{
char data;
unsigned char status;
while (1)
{
while (((status=USARTC0.STATUS) & USART_RXCIF_bm) == 0);
data=USARTC0.DATA;
if ((status & (USART_FERR_bm | USART_PERR_bm | USART_BUFOVF_bm)) == 0) return data;
}
}
#pragma used-
// Write a character to the USARTC0 Transmitter
// USARTC0 is used as the default output device by the 'putchar' function
// #define _ALTERNATE_PUTCHAR_ is inserted for this purpose
// in the main program source file before #include <stdio.h>
#pragma used+
void putchar(char c)
{
while ((USARTC0.STATUS & USART_DREIF_bm) == 0);
USARTC0.DATA=c;
}
#pragma used-
//____________________________________________________________________________________________________ _________________
.
.
.
void somo_cmd(unsigned char cmd,unsigned char feedback,unsigned char para1,unsigned char para2);
.
.
.
somo_cmd(0x0F,0x00,0x01,0x01); // Play specifing folder (01) and track (01)
.
.
.
//____________________________________________________________________________________________________ _________________
void somo_cmd(unsigned char cmd,unsigned char feedback,unsigned char para1,unsigned char para2)
{
unsigned int chk;
unsigned char chk1;
unsigned char chk2;
chk = 0xFFFF - ((unsigned int)cmd + (unsigned int)feedback + (unsigned int)para1 + (unsigned int)para2) + 0x0001;
chk1 = (unsigned char)(chk >> 8);
chk2 = (unsigned char)chk;
putchar(0x7E);
putchar(cmd);
putchar(feedback);
putchar(para1);
putchar(para2);
putchar(chk1);
putchar(chk2);
putchar(0xEF);
delay_ms(100);
}
//____________________________________________________________________________________________________ _________________
Comment