码迷,mamicode.com
首页 > 其他好文 > 详细

crazyflie2.0原理图之STM32F405与nRF51822串口1M速率的接收和发送

时间:2015-08-17 01:12:54      阅读:442      评论:0      收藏:0      [点我收藏+]

标签:

1,状态记录:

目前的状态:
(1)STM32F405R程序下载没有问题,LED测试程序OK

(2)nRF51822 256K程序下载没有问题,LED测试程序OK

(3)STM32F405R驱动MPU9250没有问题,可以正确的读取到ID

(4)nRF51822 256K的crazyflie20程序可以下载,可以进入Bootloader,从手机端看到nRF51822 BLE的信息

(5)尝试测试PWM,使得电机4转起来,看上去转动也没有问题

(6)尝试通过ST-Link调试STM32F405R,没有问题

(7)STM32F405R与nRF51822的串口调试通过

(8)STM32F405R驱动EEPROM 24AA64FT成功,板子上rework了两个上拉1K的电阻,才可以成功读取写入数据

下一步需要调试的电路:

(1)买个锂电池,BQ24075电源控制电路;

(2)BLE虽然可以识别到,但是上位机crazyflie PC client总是无法识别crazyflie2.0,所以需要进一步确认crazyradio是否真的把数据通过esb无线发送出去。

(3)LPS25H气压计由于焊接问题,目前驱动读不到数据

2,串口部分

STM32F405R这边串口用了三个引脚RX,TX和CTS(Flow Control),所以nRF51822那边同样用到三个引脚分别是TX,RX和RTS,从nRF51822的datasheet可以看到有关RTS部分的讲解,看如下图可以知道,当RTS拉低的时候STM32F405R串口可以发送数据,当RTS拉高的时候,相当于通知STM32F405R先不要发送数据。

技术分享

从原理图上看,STM32F405R这边连接的Flow control引脚是PA4,为了验证分析的正确性,看了下crazyflie-firmware\drivers\src\uart_syslink.c中看到如下程序:

#define UART_TXEN_PERIF       RCC_AHB1Periph_GPIOA
  #define UART_TXEN_PORT        GPIOA
  #define UART_TXEN_PIN         GPIO_Pin_4
  #define UART_TXEN_EXTI        EXTI_Line4
void uartInit(void)
{
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  EXTI_InitTypeDef extiInit;

  /* Enable GPIO and USART clock */
  RCC_AHB1PeriphClockCmd(UART_GPIO_PERIF, ENABLE);
  ENABLE_UART_RCC(UART_PERIF, ENABLE);

  /* Configure USART Rx as input floating */
  GPIO_InitStructure.GPIO_Pin   = UART_GPIO_RX_PIN;
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(UART_GPIO_PORT, &GPIO_InitStructure);

  /* Configure USART Tx as alternate function */
  GPIO_InitStructure.GPIO_Pin   = UART_GPIO_TX_PIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_Init(UART_GPIO_PORT, &GPIO_InitStructure);

  //Map uart to alternate functions
  GPIO_PinAFConfig(UART_GPIO_PORT, UART_GPIO_AF_TX_PIN, UART_GPIO_AF_TX);
  GPIO_PinAFConfig(UART_GPIO_PORT, UART_GPIO_AF_RX_PIN, UART_GPIO_AF_RX);

#if defined(UART_OUTPUT_TRACE_DATA) || defined(ADC_OUTPUT_RAW_DATA) || defined(IMU_OUTPUT_RAW_DATA_ON_UART)
  USART_InitStructure.USART_BaudRate            = 2000000;
  USART_InitStructure.USART_Mode                = USART_Mode_Tx;
#else
  USART_InitStructure.USART_BaudRate            = 1000000;
  USART_InitStructure.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
#endif
  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_CTS;
  USART_Init(UART_TYPE, &USART_InitStructure);

  uartDmaInit();

  // TODO: Enable
  // Configure Tx buffer empty interrupt
  NVIC_InitStructure.NVIC_IRQChannel = UART_IRQ;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_UART_PRI;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  vSemaphoreCreateBinary(waitUntilSendDone);
  uartDataDelivery = xQueueCreate(40, sizeof(uint8_t));

  USART_ITConfig(UART_TYPE, USART_IT_RXNE, ENABLE);

  //Setting up TXEN pin (NRF flow control)
  RCC_AHB1PeriphClockCmd(UART_TXEN_PERIF, ENABLE);

  bzero(&GPIO_InitStructure, sizeof(GPIO_InitStructure));
  GPIO_InitStructure.GPIO_Pin = UART_TXEN_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(UART_TXEN_PORT, &GPIO_InitStructure);
  extiInit.EXTI_Line = UART_TXEN_EXTI;
  extiInit.EXTI_Mode = EXTI_Mode_Interrupt;
  extiInit.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  extiInit.EXTI_LineCmd = ENABLE;
  EXTI_Init(&extiInit);
  NVIC_EnableIRQ(EXTI4_IRQn);
  //Enable UART
  USART_Cmd(UART_TYPE, ENABLE);
  
  isInit = true;
}
void uartTxenFlowctrlIsr()
{
  EXTI_ClearFlag(UART_TXEN_EXTI);
//上升沿,关闭dma,停止发送
  if (GPIO_ReadInputDataBit(UART_TXEN_PORT, UART_TXEN_PIN) == Bit_SET)
  {
    uartPauseDma();
    //ledSet(LED_GREEN_R, 1);
  }
  else//下降沿,打开dma,恢复发送
  {
    uartResumeDma();
    //ledSet(LED_GREEN_R, 0);
  }
}

上面的中断程序通过如下中断程序引用,这个pin就是在检测nRF51822 RTS p0.14的上升沿和下降沿

void DONT_DISCARD EXTI4_IRQHandler(void)

{
  uartTxenFlowctrlIsr();
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

crazyflie2.0原理图之STM32F405与nRF51822串口1M速率的接收和发送

标签:

原文地址:http://blog.csdn.net/xingqingly/article/details/47708201

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!