http://www.vlsi.fi/en/products/vs1053.html
Das Breakoutboard mit 12.288Mhz Quarz:
https://download.mikroe.com/documents/a ... l-v100.pdf
Das Teil hab ich an einen STM32F407 Discoveryboard an SPI1 getüdelt.
Chan FATFS läut über SDIO an einer SD-Karte soweit problemlos.
Zum Problem:
Nach der Resetprozedur, das Staus Register auslesen, da fängt es an, ich lese nur 0 raus. DREQ kommt aber zurück.
Wenn mann das Ignoriert und dann ein paar weitere Register zur Initialisierung beschriebt und dann MP3 reinschiebt, kommt zwar DREQ jeweils.
Beim MP3 reinschieben kommt die DREQ anfrage frequenz auch passend zur MP3 Bitrate vom File. Sound kommt aber noch keiner raus.
Bei weiteren Register beschreiben kommen gelegentlich Daten raus aus dem VS1053
Irgendwie hab ich das gefühl dass der den SPI nicht richtig liest. Pegel und flanken mitn Oszi schauen soweit gut aus. SPI Initialisirungstakt hab ich auch schon rumgespielt.
Code: Alles auswählen
/* Commands */
#define VS1053_WRITE_CMD 0x02;
#define VS1053_READ_CMD 0x03;
/* Registers */
const uint8_t VS1053_REG_BASE = 0x00;
const uint8_t VS1053_REG_MODE = 0x00;
const uint8_t VS1053_REG_STATUS = 0x01;
const uint8_t VS1053_REG_BASS = 0x02;
const uint8_t VS1053_REG_CLOCKF = 0x03;
const uint8_t VS1053_REG_DECODE_TIME = 0x04;
const uint8_t VS1053_REG_AUDATA = 0x05;
const uint8_t VS1053_REG_WRAM = 0x06;
const uint8_t VS1053_REG_WRAMADDR = 0x07;
const uint8_t VS1053_REG_HDAT0 = 0x08;
const uint8_t VS1053_REG_HDAT1 = 0x09;
const uint8_t VS1053_REG_AIADDR = 0x0A;
const uint8_t VS1053_REG_VOL = 0x0B;
const uint8_t VS1053_REG_AICTRL0 = 0x0C;
const uint8_t VS1053_REG_AICTRL1 = 0x0D;
const uint8_t VS1053_REG_AICTRL2 = 0x0E;
const uint8_t VS1053_REG_AICTRL3 = 0x0F;
Code: Alles auswählen
bool VS1053_Init()
{
uint16_t status = 0;
XCS_HIGH; /* XCS High */
XDCS_HIGH; /* XDCS High */
VS1053_Reset(); /* Hard Reset */
/* x 1.0 Clock, 12MHz / 7, SPI Baudrate should be less than 1.75MHz */
(HSPI_VS1053)->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; /* 42MHz / 32 = 1.31MHz */
if(HAL_SPI_Init(HSPI_VS1053) != HAL_OK) return false;
VS1053_Reset(); //Hardware Reset
//VS1053_SoftReset();
/* Read Status to check SPI */
if(!VS1053_SciRead(VS1053_REG_STATUS, &status)) return false; //Hier ist das Glump
if(((status >> 4) & 0x0F) != 0x04) return false;
/* MP3 Mode GPIO configuration */
if(!VS1053_SciWrite(VS1053_REG_WRAMADDR, 0xC017)) return false; /* GPIO direction */
if(!VS1053_SciWrite(VS1053_REG_WRAM, 3)) return false;
if(!VS1053_SciWrite(VS1053_REG_WRAMADDR, 0xC019)) return false; /* GPIO output */
if(!VS1053_SciWrite(VS1053_REG_WRAM, 0)) return false;
/* Soft reset */
if(!VS1053_SoftReset()) return false;
/* x3.0 Clock, 36MHz / 7, SPI Baudrate should be less than 5.14MHz */
if(!VS1053_SciWrite(VS1053_REG_CLOCKF, 0x6000)) return false;
(HSPI_VS1053)->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; /* 42MHz / 16 = 2.625MHz */
if(HAL_SPI_Init(HSPI_VS1053) != HAL_OK) return false;
/* Read Status to check SPI */
if(!VS1053_SciRead(VS1053_REG_STATUS, &status)) return false;
if(((status >> 4) & 0x0F) != 0x04) return false;
/* Read endFill Byte */
uint16_t regVal;
if(!VS1053_SciWrite(VS1053_REG_WRAMADDR, 0x1E06)) return false; /* endFill */
if(!VS1053_SciRead(VS1053_REG_WRAM, ®Val)) return false;
endFillByte = regVal & 0xFF;
return true;
}
void VS1053_Reset()
{
uint8_t dummy = 0xFF;
XRST_LOW; /* XRST Low */
HAL_SPI_Transmit(HSPI_VS1053, &dummy, 1, 10); /* Tx Dummy */
HAL_Delay(100); /* 10ms Delay */
XRST_HIGH; /* XRST High */
HAL_Delay(100);
}
/* SCI Tx */
bool VS1053_SciWrite( uint8_t address, uint16_t input )
{
uint8_t buffer[4];
buffer[0] = VS1053_WRITE_CMD;
buffer[1] = address;
buffer[2] = input >> 8; /* Input MSB */
buffer[3] = input & 0x00FF; /* Input LSB */
while (HAL_GPIO_ReadPin(VS1053_DREQ_PORT, VS1053_DREQ_PIN) == GPIO_PIN_RESET); /* Wait DREQ High */
XCS_LOW; /* XCS Low */
if(HAL_SPI_Transmit(HSPI_VS1053, buffer, sizeof(buffer), 10) != HAL_OK) return false;
XCS_HIGH; /* XCS High */
while (HAL_GPIO_ReadPin(VS1053_DREQ_PORT, VS1053_DREQ_PIN) == GPIO_PIN_RESET); /* Wait DREQ High */
return true;
}
/* SCI TxRx */
bool VS1053_SciRead( uint8_t address, uint16_t *res)
{
uint8_t dummy = 0xFF;
uint8_t txBuffer[2];
uint8_t rxBuffer[2];
txBuffer[0] = VS1053_READ_CMD;
txBuffer[1] = address;
while(HAL_GPIO_ReadPin(VS1053_DREQ_PORT, VS1053_DREQ_PIN) == GPIO_PIN_RESET); /* Wait DREQ High */
XCS_LOW; /* XCS Low */
if(HAL_SPI_Transmit(HSPI_VS1053, txBuffer, sizeof(txBuffer), 10) != HAL_OK) return false;
if(HAL_SPI_TransmitReceive(HSPI_VS1053, &dummy, &rxBuffer[0], 1, 10) != HAL_OK) return false;
if(HAL_SPI_TransmitReceive(HSPI_VS1053, &dummy, &rxBuffer[1], 1, 10) != HAL_OK) return false;
XCS_HIGH; /* XCS High */
*res = rxBuffer[0]; /* Received data */
*res <<= 8; /* MSB */
*res |= rxBuffer[1]; /* LSB */
while (HAL_GPIO_ReadPin(VS1053_DREQ_PORT, VS1053_DREQ_PIN) == GPIO_PIN_RESET); /* Wait DREQ High */
return true;
}
/* SDI Tx */
bool VS1053_SdiWrite( uint8_t input )
{
while (HAL_GPIO_ReadPin(VS1053_DREQ_PORT, VS1053_DREQ_PIN) == GPIO_PIN_RESET); /* Wait DREQ High */
XDCS_LOW; /* XDCS Low(SDI) */
if(HAL_SPI_Transmit(HSPI_VS1053, &input, 1, 10) != HAL_OK) return false; /* SPI Tx 1 byte */
XDCS_HIGH; /* XDCS High(SDI) */
return true;
}
/* SDI Tx 32 bytes */
bool VS1053_SdiWrite32( uint8_t *input32 )
{
while (HAL_GPIO_ReadPin(VS1053_DREQ_PORT, VS1053_DREQ_PIN) == GPIO_PIN_RESET); /* Wait DREQ High */
XDCS_LOW; /* XDCS Low(SDI) */
if(HAL_SPI_Transmit(HSPI_VS1053, input32, 32, 10) != HAL_OK) return false; /* SPI Tx 32 bytes */
XDCS_HIGH; /* XDCS High(SDI) */
return true;
}
bool VS1053_SoftReset()
{
if(!VS1053_SciWrite(VS1053_REG_MODE, 0x4804)) return false; /* SM LINE1 | SM SDINEW | SM RESET */
HAL_Delay(100);
return true;
}
Code: Alles auswählen
static void MX_SPI1_Init(void)
{
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}