VS1053 recording example

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
pradeepsysargus
User
Posts: 3
Joined: Tue 2016-12-27 6:31

Re: VS1053 recording example

Post by pradeepsysargus » Fri 2017-01-06 13:46

Some issue was found with writing register values and reading them back..
Not getting the same value that was written to the register..

When tried to write two or three times .. I guess it is taking a proper value.

The registers and its value that is set in order are:
SCI_WRAMADDR, 0xC01A
SCI_WRAM, 0x2
SCI_AICTRL1, 0x400
SCI_AICTRL2, 0x0
SCI_AICTRL3, 0x0
SCI_AIADDR, 0x34 (After plugin success)..

Is it common to set the register values 2 to 3 times .. ?

Also, either due to a grounding issue on board or due to software bug it is getting stuck in SpiLoadImageInto1053() sometimes.. We are using wires to connect LCSoft vs1053 or Adafruit vs1053 with STM32F4xx board. When the common ground between vs1053 and stm32 is removed and put back..we are able to proceed further in the code..come out of SpiLoadImageInto1053(), but not getting the proper load address at SCI_AIADDR sometimes.

I am using the code of SpiLoadImageInto1053() as in page 33 of VorbisEncoder170c pdf.

During initialization, I read HDAT0 and HDAT1 values.. which are zero

User avatar
pasi
VLSI Staff
Posts: 1560
Joined: Thu 2010-07-15 16:04

Re: VS1053 recording example

Post by pasi » Mon 2017-01-09 16:37

pradeepsysargus wrote:Is it common to set the register values 2 to 3 times .. ?
No, and it would be disastrous to do that to SCI_WRAM.

But note that the firmware changes the contents of some of the SCI registers, so which registers are you using for the read+write testing?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

lauba1
User
Posts: 17
Joined: Wed 2017-01-11 9:26

Re: VS1053 recording example

Post by lauba1 » Mon 2017-01-16 22:03

Hello all;)
I have question if I need a lot of changes if I want to run this example on VS1063 with STM uC?. And also I want to load the plugin from uC memory to VLSI but here is my question what is the best solution to check if plugin is loaded ok?. And the last question if I want to write the recording voice simultanously to sd card, where I use FfatFS library is possible if I am using delay/blocking function in SPI ?
Like this:

Regards lauba.

Code: Select all

static uint8_t SpiTransmitReceive(uint8_t u8DataTransmitt )
{
	uint8_t u8DataRecevie = 0u;
	while ((HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY));
	HAL_SPI_TransmitReceive(&hspi2, &u8DataTransmitt, &u8DataRecevie, 1, 5000);
	return u8DataRecevie;
}


void WriteSci(u_int8 addr, u_int16 data)
{
	while(!HAL_GPIO_ReadPin(DREQ_GPIO_Port,DREQ_Pin))	/*Check if DREQ is low - if is low can't  */
	{
		; /*wait*/
	}
	VsSelectChip();
	SpiTransmitReceive(VS_WRITE_COMMAND);
	SpiTransmitReceive(addr);
	SpiTransmitReceive((uint8_t)(data>>8)); /*Send high byte*/
	SpiTransmitReceive((uint8_t)(data&0xFF)); /*Send low byte*/
	VsDeselectChip();
}

u_int16 ReadSci(u_int8 addr)
{
	uint8_t u8InHigh;
	uint8_t u8InLow;
	while(!HAL_GPIO_ReadPin(DREQ_GPIO_Port,DREQ_Pin))	/*Check if DREQ is low - if is low can't  */
	{
		; /*wait*/
	}
	VsSelectChip();
	SpiTransmitReceive(VS_READ_COMMAND);
	SpiTransmitReceive(addr);
	u8InHigh  = SpiTransmitReceive(0xFF); /* High Byte */
	u8InLow   = SpiTransmitReceive(0xFF); /* Low Byte */
	VsDeselectChip();
	return ((uint16_t)u8InHigh<<8) + u8InLow;
}

User avatar
Henrik
VLSI Staff
Posts: 1136
Joined: Tue 2010-06-22 14:10

Re: VS1053 recording example

Post by Henrik » Tue 2017-01-17 11:42

Hello!
pradeepsysargus wrote:The data that we are getting at the line wordsWaiting = vs1053_ReadRegister(SCI_HDAT1) is like 64KBytes, it is taking lot of time to put that data to "MyRecord.ogg" file. It writes in chunks of 256 words (512 bytes) as defined by the for loop:
The Ogg Vorbis encoder buffer for VS1053, is 8 kilobytes, or 4 16-bit kilowords, so you should never get larger values than 4095. And as Pasi said, after initial headers the size should only be perhaps around 700-750 words.

To test what your issue with the register is, reset the VS1053, then write / read random numbers to SCI_AICTRL0 through SCI_AICTRL3. These registers don't do anything in normal operation mode. Also check that you don't use too high SPI speed: for write max. 1/4 of VS1053's internal clock, for read max. 1/7 of VS1053's internal clock. Also check clock polarity: write on falling edge, read on rising edge.

Kind regards,
- Henrik
Good signatures never die. They just fade away.

User avatar
Henrik
VLSI Staff
Posts: 1136
Joined: Tue 2010-06-22 14:10

Re: VS1053 recording example

Post by Henrik » Tue 2017-01-17 11:48

Hello Lauba!
lauba1 wrote:Hello all;)
I have question if I need a lot of changes if I want to run this example on VS1063 with STM uC?.
Your code looks good. I can't find any errors.
And also I want to load the plugin from uC memory to VLSI but here is my question what is the best solution to check if plugin is loaded ok?.
You could perhaps check whether the plugin's first 16 output bytes to SCI_HDAT0 / SCI_HDAT1 are correct? There really is no checksum or similar mechanism to verify loads.
And the last question if I want to write the recording voice simultanously to sd card, where I use FfatFS library is possible if I am using delay/blocking function in SPI ?
I am not sure if I understand the question. If the SD card blocks, you have time until the Ogg Vorbis encoder 8 KiB stream FIFO overflows. So, as an example, at 128 kbit/s typical rate (16 KB/s), you then have up to 0.5 seconds to get your SD card operations sorted out if it blocks. If you get delays longer than that, then the Ogg Vorbis buffer will overflow, and cause an incorrect file.

Kind regards,
- Henrik
Good signatures never die. They just fade away.

lauba1
User
Posts: 17
Joined: Wed 2017-01-11 9:26

Re: VS1053 recording example

Post by lauba1 » Tue 2017-01-17 12:00

Thanks Henrik, I will implement the code and give you feedback or question if the problem will occur;)
see you later!;)

lauba1
User
Posts: 17
Joined: Wed 2017-01-11 9:26

Re: VS1053 recording example

Post by lauba1 » Wed 2017-01-18 10:04

Hello Henrik again;)
So I write here my code but I changed the approach and I write record voice in mp3 format in VLSI 1063 so if better run the new topic instead of here pls do this;)

So for now I will explain step by step about my approach which is looking on your solution added on this forum;)
I repeated I use VLSI 1063 + STM32F0 = Save mp3 record voice to SD card using fatFS library.
So I have the main function :

Code: Select all

/*
  Main function that activates recording.
*/
int VSTestHandleFile(void)
{
	FRESULT s_ResultObject;
	FIL outFP ;

	/*  Now open output file. It's better to do this before activating
	  recording so that even if opening the output file is slow,
	  you will not lose data. */
	s_ResultObject = f_mount(&s_FatFsObject,(const TCHAR*)"",(BYTE)0);
	if(s_ResultObject == 0u)
	{
		s_ResultObject = f_open (&outFP, "tdws.mp3", FA_WRITE | FA_OPEN_ALWAYS);
		if(s_ResultObject == 0u)
		{
			s_ResultObject = f_lseek(&outFP, 0);
		}
	}
	s_ResultObject = f_truncate(&outFP);
	
	if (VSTestInitHardware() || VSTestInitSoftware())
	{
		return 1;
		/*fail*/
	}
	HAL_GPIO_WritePin(RED_LED_GPIO_Port,RED_LED_Pin,RESET);
	VS1063RecordFile(outFP);
	/*If record end than go to while loop and blinking the diode*/
	while(1)
	{
	  HAL_GPIO_TogglePin(RED_LED_GPIO_Port,RED_LED_Pin);
	  HAL_Delay(800);
	}

	return 0 ; /*means success*/
}
So in VSTestInitHardware() I do hardware reset by pin.

Code: Select all

int VSTestInitHardware(void)
{
	/*Configure Chip Select Pin for command and data to high logic level */
	HAL_GPIO_WritePin(VLSI_CS_GPIO_Port, VLSI_CS_Pin, GPIO_PIN_SET);
	HAL_GPIO_WritePin(XDCS_GPIO_Port, XDCS_Pin, GPIO_PIN_SET);
	/*Configure GPIO pin Restet and chip select from SD CARD to high logic level */
	HAL_GPIO_WritePin(GPIOA, XRESET_Pin|CS_PIN_Pin, GPIO_PIN_SET);
	/*Hardware RESET*/
	HAL_GPIO_WritePin(GPIOA, XRESET_Pin, GPIO_PIN_RESET);
	/*some delay*/
	HAL_Delay(30);
	/*End Hardware RESET*/
	HAL_GPIO_WritePin(GPIOA, XRESET_Pin, GPIO_PIN_SET);
	/*some delay*/
	HAL_Delay(10);

	return 0; /*Hw init success*/
}

In VSTestInitSoftware() I do:

Code: Select all

int VSTestInitSoftware(void)
{
	u_int16 ssVer = 0;
	u_int16 u16ReadData = 0;
	/* Start initialization with a dummy read, which makes sure our
	   microcontoller chips selects and everything are where they
	   are supposed to be and that VS10xx's SCI bus is in a known state. */
	   u16ReadData = ReadSci(SCI_MODE);
	/* First real operation is a software reset. After the software
	   reset we know what the status of the IC is. You need, depending
	   on your application, either set or not set SM_SDISHARE. See the
	   Datasheet for details. */
	  WriteSci(SCI_MODE, SM_SDINEW | SM_RESET);
	  /* A quick sanity check: write to two registers, then test if we
	     get the same results. Note that if you use a too high SPI
	     speed, the MSB is the most likely to fail when read again. */
	  WriteSci(SCI_AICTRL1, 0xABAD);
	  WriteSci(SCI_AICTRL2, 0x7E57);
	  if (ReadSci(SCI_AICTRL1) != 0xABAD || ReadSci(SCI_AICTRL2) != 0x7E57)
	  {
	    /*printf("There is something wrong with VS10xx SCI registers\n");*/
	    return 1;
	  }
	  WriteSci(SCI_AICTRL1, 0);
	  WriteSci(SCI_AICTRL2, 0);
	  /* Check VS10xx type */
	  ssVer = ((ReadSci(SCI_STATUS) >> 4) & 15);
	  if (chipNumber[ssVer])
	  {
	      /*printf("Chip is VS%d\n", chipNumber[ssVer]);*/
	      if (chipNumber[ssVer] != 1063)
	      {
	        /*printf("Incorrect chip\n");*/
	        return 1;
	      }
	   }
	   else
	   {
	      /*printf("Unknown VS10xx SCI_MODE field SS_VER = %d\n", ssVer);*/
	      return 1;
	   }

	  /* If we are running right chip there is time to configure necessary hardware to limmit dissipated power*/
	  /*Switch off audio output amplifier*/
	  WriteSci(SCI_VOL, 0xFFFF);

	  /* Set the clock. Until this point we need to run SPI slow so that
	     we do not exceed the maximum speeds mentioned in
	     Chapter SPI Timing Diagram in the Datasheet.
		 The goal is just to use VLSI as MP3 encoder */
	  WriteSci(SCI_CLOCKF, SC_MULT_53_45X | SC_ADD_53_00X | HZ_TO_SC_FREQ(12288000) );
	  /* Now when we have upped the VS10xx clock speed, the microcontroller
	     SPI bus can run faster. Do that before you start playing or
	     recording files. */
	  /*So change the vlsi SPI to 8 Mhz*/
	  hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
	  if (HAL_SPI_Init(&hspi2) != HAL_OK)
	  {
	    Error_Handler();
	  }
	  /* Now it's time to load the proper patch set. */
	  LoadPlugin(plugin, sizeof(plugin)/sizeof(plugin[0]));

	  HAL_Delay(10);
	  WriteSci(SCI_RECRATE,24000); /*Write to SCI_AICTRL0 samplerate set to 24000*/
	  WriteSci(SCI_RECGAIN, 1024); /* AICTRL1 - encoding gain 1024 = gain 1 = best quality */
	  WriteSci(SCI_RECMODE, RM_63_UART_TX | RM_63_FORMAT_MP3 | RM_63_ADC_MODE_RIGHT); /*SCI_AICTRL3 - encoding format - mp3, ADC set to right channel*/
	  if(1)
	  {
		  /* Example of VBR mode */
		  WriteSci(SCI_RECQUALITY, RQ_MODE_VBR | RQ_MULT_1000 | 160); /* ~160 kbps */
	  }
	  else
	  {
		  /* Example of CBR mode */
		  WriteSci(SCI_RECQUALITY, RQ_MODE_CBR | RQ_MULT_1000 | 160); /*  160 kbps */
	  }
	  /* We're ready to go. */
	  return 0;
}
Here is how I connected the vlsi:
[img]
vlsi.jpg
vlsi.jpg (44.4 KiB) Viewed 1664 times
[/img]

Regards lauba
Last edited by lauba1 on Thu 2017-01-19 11:00, edited 2 times in total.

lauba1
User
Posts: 17
Joined: Wed 2017-01-11 9:26

Re: VS1053 recording example

Post by lauba1 » Wed 2017-01-18 13:42

Here is the file which I got. When I see inside it looks like I am getting only header?
Attachments
MCDWS.MP3
(233.33 KiB) Downloaded 80 times

User avatar
pasi
VLSI Staff
Posts: 1560
Joined: Thu 2010-07-15 16:04

Re: VS1053 recording example

Post by pasi » Wed 2017-01-18 14:24

WriteSci(SCI_VOL, 0xFFFF);
0xffff turns off all analog, including the ADC. The encoding mode does enable power, but SCI_VOL being 0xffff may disable analog power later.

So, try SCI_VOL = 0xfefe or maybe 0x0c0c to monitor the encoding. If you don't get any output, the encoder will get no input either.

In addition, the file has suspicious strings of zeroes. You may be reading the number of words available wrong. Is your SPI clock speed lower than 1/7 of CLKI?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

lauba1
User
Posts: 17
Joined: Wed 2017-01-11 9:26

Re: VS1053 recording example

Post by lauba1 » Wed 2017-01-18 15:40

SPI clock from uC to SPI is set to 8 Mhz and the clk in VLSI is set like this:
WriteSci(SCI_CLOCKF, SC_MULT_53_45X | SC_ADD_53_00X | HZ_TO_SC_FREQ(12288000) );

So is about 1/7. I checked with different SCI_VOL value and with setting 0xFEFE I got some info in file detailed but still not look good.
What do you think about
"You may be reading the number of words available wrong." ?
Attachments
MDWS.MP3
(189.06 KiB) Downloaded 61 times

Post Reply