但你的程序中存在着几个潜在的错误,这种错误不是任何编译器都能容忍的
一、先看程序的全局变量定义部分,定义了一个无符号整型数值型变量 DA_data
即 int 类型的变量
二、之后的自定义函数中又定义了一个无符号长整型数值型变量 DA_date_buf
即 long 类型变量
三、然而这个函数中,又调用了其它函数,并指定了数据类型为无符号字符型变量
即 char 类型变量
四、在函数中,又对数值型的变量进行了位 *** 作,即右移 *** 作,DA_date_buf>>8
这种类型上的区别,某些编译器可以通过,但某些编译器不能通过,不能通过的编译器,则会发生数据类型错误,有时候编译器是无法判断出问题所在的,即不能提示出具体错在哪里。
解决办法则是:
一、数据要是不大的话,可以全部使用 char 字符型变量,因为只有字符型变量才支持左移和右移的位 *** 作,字符型变量转换成十进制表示,最小数值到最大数值是 0 ~ 254 共255个单位
二、数值比较大的时候,就不要进行位 *** 作,即左移与右移的 *** 作,可以用数值表达式予以替换,即 DA_date_buf=(DA_date_buf + 8)或 DA_date_buf=(DA_date_buf - 8)
这个是驱动程序:#include "CS4344.h"
DMA_InitTypeDef DMA_InitStructure
u32 AudioTotalSize=0xFFFF
u32 AudioRemSize =0
u16 *CurrentPos
extern void AUDIO_TransferComplete(u32 pBuffer, uint32_t Size)
void AUDIO_Init(u32 AudioFreq)
{
I2S_GPIO_Init()
Audio_I2S_Init(AudioFreq)
Audio_DMA_Init()
}
void I2S_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE)
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13 | GPIO_Pin_15
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL
GPIO_Init(GPIOB, &GPIO_InitStructure)
GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_SPI2)
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2)
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL
GPIO_Init(GPIOC, &GPIO_InitStructure)
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_SPI2)
}
void Audio_I2S_Init(uint32_t AudioFreq)
{
I2S_InitTypeDef I2S_InitStructure
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE)
SPI_I2S_DeInit(SPI2)
/* I2S peripheral configuration */
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable
I2S_InitStructure.I2S_AudioFreq = AudioFreq
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx
I2S_Init(SPI2, &I2S_InitStructure)
//I2S_Cmd(SPI2, ENABLE)
}
void Audio_DMA_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE)
DMA_Cmd(DMA1_Stream4, DISABLE)
DMA_DeInit(DMA1_Stream4)
DMA_InitStructure.DMA_Channel = DMA_Channel_0
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x4000380C
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)0
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral
DMA_InitStructure.DMA_BufferSize = (uint32_t)0xFFFE
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal
DMA_InitStructure.DMA_Priority = DMA_Priority_High
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single
DMA_Init(DMA1_Stream4, &DMA_InitStructure)
DMA_ITConfig(DMA1_Stream4, DMA_IT_TC, ENABLE)
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream4_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE
NVIC_Init(&NVIC_InitStructure)
SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)