OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4414|回复: 5

stm32单总线的例程问题,有用过的没

[复制链接]

1

主题

5

帖子

0

精华

新手上路

积分
27
金钱
27
注册时间
2016-2-12
在线时间
6 小时
发表于 2016-3-6 21:44:06 | 显示全部楼层 |阅读模式
6金钱
stm32固件库里面关于单总线的例程,怎么一直在卡在        
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET)
{};
是两个usart的TX直接相连就可以吗?
谢谢

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2016-3-6 22:14:47 | 显示全部楼层
回复

使用道具 举报

1

主题

5

帖子

0

精华

新手上路

积分
27
金钱
27
注册时间
2016-2-12
在线时间
6 小时
 楼主| 发表于 2016-3-7 00:15:05 | 显示全部楼层

void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);

uint8_t com_correct = 8;
uint8_t TxBuffer1[2] = {1, 2};
uint8_t TxBuffer2[2] = {10, 20};
uint8_t RxBuffer1[2];
uint8_t RxBuffer2[2];

int main(void)
{               
        //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÖD¶ÏóÅÏè¼¶·Ö×éÎa×é2£o2λÇàÕ¼óÅÏè¼¶£¬2λÏìó|óÅÏè¼¶
        delay_init();                     //Ñóê±oˉêy3õê¼»ˉ          
        //uart_init(115200);         //′®¿ú3õê¼»ˉÎa115200
  LED_Init();
// USART1_init();     //PA3 TX; PA9 TX
        RCC_Configuration();
        GPIO_Configuration();
        USART_Configuration();
         
  while(1)
        {
                if(com_correct == 8)
                {
                        //com_correct = USART1_ReadByte();
                        delay_ms(500);//500ms

                        /* Wait until end of transmit */
                        while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
                        {
                        }
                        /* Write one byte in the USARTy Transmit Data Register */
                        USART_SendData(USART1, TxBuffer1[0]);
                        /* Wait until end of transmit */
                        while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
                        {
                        }
                        /* Wait the byte is entirely received by USARTz */  
                        while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET)
                        {
                        }
                        /* Store the received byte in the RxBuffer2 */
                        RxBuffer2[0] = USART_ReceiveData(USART2);

                        /* Clear the USART1 Data Register */
                        USART_ReceiveData(USART1);               
                       
                        /* Wait until end of transmit */
                        while(USART_GetFlagStatus(USART2, USART_FLAG_TXE)== RESET)
                        {
                        }
                        /* Write one byte in the USARTz Transmit Data Register */
                        USART_SendData(USART2, TxBuffer2[0]);

                        /* Wait the byte is entirely received by USARTy */
                        while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE) == RESET)
                        {
                        }
                        /* Store the received byte in the RxBuffer1 */
                        RxBuffer1[0] = USART_ReceiveData(USART1);
          }
                delay_ms(500);//500ms               
                com_correct = 0;
                       
        }         
}

/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
  /* Enable GPIO clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);  
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);

}

/**
  * @brief  Configures the different USART.
  * @param  None
  * @retval None
  */
void USART_Configuration(void)
{
/* USARTy and USARTz configuration -------------------------------------------*/
  /* USARTy and USARTz configured as follow:
        - BaudRate = 230400 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
        USART_InitTypeDef USART_InitStructure;
  USART_InitStructure.USART_BaudRate = 230400;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  /* Configure USARTy */
  USART_Init(USART1, &USART_InitStructure);
  /* Configure USARTz */
  USART_Init(USART2, &USART_InitStructure);
  
  /* Enable the USARTy */
  USART_Cmd(USART1, ENABLE);
  /* Enable the USARTz */
  USART_Cmd(USART2, ENABLE);

  /* Enable USARTy Half Duplex Mode*/
  USART_HalfDuplexCmd(USART1, ENABLE);
  /* Enable USARTz Half Duplex Mode*/
  USART_HalfDuplexCmd(USART2, ENABLE);
}
/**
  * @brief  Configures the different GPIO ports.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable the USART3 Pins Software Remapping */
  //GPIO_PinRemapConfig(GPIO_Remap_USART1 | GPIO_Remap_USART2, ENABLE);
        GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
        GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);

  
  /* Configure USARTy Tx as alternate function open-drain */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure USARTz Tx as alternate function open-drain */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
}
回复

使用道具 举报

1

主题

5

帖子

0

精华

新手上路

积分
27
金钱
27
注册时间
2016-2-12
在线时间
6 小时
 楼主| 发表于 2016-3-7 00:15:55 | 显示全部楼层

参照固件库里面的例子改的,用的是PA2,PA9
回复

使用道具 举报

1

主题

5

帖子

0

精华

新手上路

积分
27
金钱
27
注册时间
2016-2-12
在线时间
6 小时
 楼主| 发表于 2016-3-8 22:37:03 | 显示全部楼层
没人会吗?自己顶
回复

使用道具 举报

3

主题

69

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
255
金钱
255
注册时间
2014-2-2
在线时间
41 小时
发表于 2016-3-8 23:21:06 | 显示全部楼层
判断标志位没有一个是正确的。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-20 13:19

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表