Other Parts Discussed in Thread: TLV320AIC3254, CC3200, CC3200SDK, SYSBIOS
Tool/software: TI-RTOS
Hello,
We are having issues with I2S on the CC3200. We are trying to play a sound file(16-bit, stereo, 16Khz sampling) from the SimpleLink file system. The file seems to read in fine from the filesystem, but no sound comes out of the TLV320AIC3254 DAC and we encounter a DMAERR interrupt after finishing. We have had it working prior when doing testing with out the TIDriver library. I know the DAC is setting up correctly as we are using the same register configuration and code from our original test bed(using I2C_Open, I2C_transfer, etc). I attached the code below
unsigned short fileBuffer[30*1024];
_u8 tBuffer[3072];
int playSound(char * fileName)
{
int offset= 0;
long DeviceFileHandle;
long lRetVal = -1; //negative retval is an error
SlFsFileInfo_t pFsFileInfo;
I2S_BufDesc bufDesc[3];
I2S_BufDesc *pDesc = NULL;
char fil[] = "ding.wav";
Semaphore_pend(slSemaphore, BIOS_WAIT_FOREVER); // Wait for NWP to access FS
Semaphore_pend(semWaterMarkHandle, BIOS_WAIT_FOREVER); // Wait until I2S handle is opened
System_printf("SOUND: Playing sound\n");
// Open File
lRetVal = sl_FsOpen((unsigned char *)&fil, FS_MODE_OPEN_READ, NULL, &DeviceFileHandle);
if(lRetVal < 0)
{
CloseSoundFile(DeviceFileHandle);
//System_printf("SOUND: Failed to read file %s\n", fileName);
return -1;
}
// Read from file and discard wav header
// get info on the file
lRetVal = sl_FsGetInfo((unsigned char *)&fil, NULL, &pFsFileInfo);
if(lRetVal < 0)
{
CloseSoundFile(DeviceFileHandle);
//System_printf("SOUND: Failed to read file %s\n", fileName);
return -1;
}
// Read from file
lRetVal = sl_FsRead(DeviceFileHandle, 0, tBuffer, 4);
if(lRetVal < 0)
{
CloseSoundFile(DeviceFileHandle);
//System_printf("SOUND: Failed to read file %s\n", fileName);
return -1;
}
// discard wav header
// read header
// check if file is a wav file
if ( ( tBuffer[0] != 'R'
|| tBuffer[1] != 'I'
|| tBuffer[2] != 'F'
|| tBuffer[3] != 'F' ))
{
System_printf("ERROR: Not wav format\n");
CloseSoundFile(DeviceFileHandle);
System_printf("SOUND: Failed to read file %s\n", fileName);
return -1;
}
System_printf("SOUND: Sound is RIFF Wave\n");
offset += sizeof(waveHeaderType);
_u8 *ptr = fileBuffer;
bufDesc[0].bufPtr = ptr;
bufDesc[0].bufSize = 3072;
ptr += 1536;
bufDesc[1].bufPtr = ptr;
bufDesc[1].bufSize = 3072;
ptr += 1536;
bufDesc[2].bufPtr = ptr;
bufDesc[2].bufSize = 3072;
ptr = fileBuffer;
System_printf("ptr: %x\n", ptr);
sl_FsRead(DeviceFileHandle, offset, tBuffer, 3072);
memcpy(bufDesc[0].bufPtr, tBuffer, 3072);
sl_FsRead(DeviceFileHandle, offset, tBuffer, 3072);
memcpy(bufDesc[1].bufPtr, tBuffer, 3072);
sl_FsRead(DeviceFileHandle, offset, tBuffer, 3072);
memcpy(bufDesc[2].bufPtr, tBuffer, 3072);
I2S_writeIssue(i2sHandle, &bufDesc[0]);
I2S_writeIssue(i2sHandle, &bufDesc[1]);
I2S_writeIssue(i2sHandle, &bufDesc[2]);
int doneReading = 0;
int i = 2;
while (!doneReading) {
i++;
ptr += 1536;
if(i==10) {
ptr = fileBuffer;
i = 0;
}
I2S_writeReclaim(i2sHandle, &pDesc);
if (pDesc == NULL)
while (1);
lRetVal = sl_FsRead(DeviceFileHandle, offset, tBuffer, 3072);
if (lRetVal < 0)
{
CloseSoundFile(DeviceFileHandle);
System_printf("SOUND: Failed to read file %s\n", fileName);
}
else if (lRetVal < 3072)
{
doneReading = 1;
}
//System_printf("ptr: %x\n", ptr);
memcpy(ptr, tBuffer, lRetVal);
pDesc->bufPtr = ptr;
pDesc->bufSize = lRetVal<3072?lRetVal: 3072;
I2S_writeIssue(i2sHandle, pDesc);
offset+=lRetVal;
}
System_printf("SOUND: Done playing sound.\n");
CloseSoundFile(DeviceFileHandle);
return 0;
}