打印

STM32F446 I2S 脚位输出 无电平

[复制链接]
345|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
菊江先生|  楼主 | 2018-7-11 21:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
有I2S 中???分析?查??平
有 BusFault_Handler 中?
//#include "stm32f10x.h"
#include "stm32f4xx.h"
#include <stdio.h>

void GPIO_Configuration(void ) ;
void USART_Configuration(void) ;
void I2S_Config(void) ;
intfputc( int ch, FILE *f ) ;
void Delay_MS(u16 ) ;
intmain(void)
{
//GPIO_Configuration() ;
USART_Configuration() ;

printf( "i2s program ....\n" ) ;

I2S_Config() ;

I2S_Cmd(SPI2, ENABLE)//???i?? run
}
void USART_Configuration()
{
GPIO_InitTypeDefGPIO_InitStructure ;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //??¯?GPIOA????
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//??¯?USART1????
//???f1???????}?_??M?g
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); //GPIOA9?_??°USART1
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); //GPIOA10?_??°USART1
GPIO_InitStructure.GPIO_Pin= GPIO_Pin_9 | GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Mode= GPIO_Mode_AF;//?_???\¯?
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz ;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP ; //±????_?????X
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //?W??
GPIO_Init( GPIOA, &GPIO_InitStructure ) ;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None ;

USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;

//USART_InitStructure.USART_LastBit = USART_LastBit_Enable;
USART_Init(USART1, &USART_InitStructure ) ;
;USART_Cmd( USART1, ENABLE ) ;
}
intputc( int ch, FILE *f )
{
while ( USART_GetFlagStatus( USART1, USART_FLAG_TC ) == RESET ) ;
eturn (ch) ;
}
void Delay_MS(u16 dly)
{
u16 i,j;
for(i=0;i<dly;i++)
for(j=1000;j>0;j--);
}
void I2S_Config(void)
{
inta ;
GPIO_InitTypeDef GPIO_InitStructure;I2S_InitTypeDef I2S_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
//RCC_APB2Periph_AFIO, ENABLE);

//RCC_I2SCLKConfig( RCC_I2SBus_APB1, RCC_I2SCLKSource_PLLI2S ) ;

RCC->DCKCFGR &= ~RCC_DCKCFGR_I2S2SRC; //?? I2S2SRC = PLLI2S_R
//RCC_PLLI2SConfig( 5, 254, 2, 3, 2 )
RCC_PLLI2SConfig( 8, 271, 0, 0, 6 ) ;

// 5, 254, 3, 3
//?]?m PLLI2SQDiv= 3
//RCC->DCKCFGR &= 0xFFFFFFE0 ;
//RCC->DCKCFGR |= 3 ;
RCC_PLLI2SCmd(ENABLE);
a = RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY );

RCC_APB1PeriphClockCmd( RCC_AHB1Periph_GPIOB| RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE);
/* SPI2 IRQ channel configuration */
NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_Init(&NVIC_InitStructure);
/* Connect I2S pins to Alternate functions */
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_PinAFConfig( GPIOC, GPIO_PinSource6,GPIO_AF_SPI2 ); //PC6 ,AF5I2S_MCK

/* Configure SPI2 pins: CK, WS and SD ---------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_DOWN; //GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;/GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_DOWN; //GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
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; //???MCK ???i
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_44k ;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx; //I2S_Mode_SlaveRx;
I2S_Init(SPI2, &I2S_InitStructure);
SPI2->I2SCFGR |= 1 << 11 / I2SMOD ¯????o?@????·|???_
SPI2->I2SCFGR |= 2 << 8 ;;// I2SCFG = 10
;//SPI_I2SPR ODD = 0, IS2DIV=2
// SPI2->I2SPR &= 0xFE00 ;
//SPI2->I2SPR |= 0x2
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, ENABLE);
//I2S_Cmd(SPI2, ENABLE)//
a = SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) ;

}
void SPI2_IRQHandler(void)
{ if ( (SPI2->SR & 0x02) == 0 )//TXE ?o°e?w??°?"D??
return ;SPI_I2S_ClearITPendingBit(SPI2, SPI_I2S_IT_TXE);SPI2->DR= 'A' ;//°
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

446

主题

447

帖子

0

粉丝