你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F107VCT6串口通信,选用的是查询方式遇到的问题

[复制链接]
question0303 提问时间:2013-3-28 21:58 /
一开始用中断通信,能够成功,但是用每次复位下,才能发送数据,所以想选择查询方式,就去掉了中断配置,其他的串口通信的配置留下,然后
TxCounter=0;
    while(TxCounter < sendBufferSize)
 {
     /* Send one byte from USART1 */
     USART_SendData(USARTy, sendBuffer[TxCounter++]);
   
     /* Loop until USART1 DR register is empty */
     while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET);
  
 }
发送过去,但是PC就是无法接收数据……
/* Includes ------------------------------------------------------------------*/
#include "config.h"
#include "collector.h"
#include "button.h"
#include "led.h"
#include "platform_config.h"
#include "stm32f10x.h"
#include "stm3210c_eval_lcd.h"
#include "stm32_eval.h"
#include
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private Variables -----------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
#define BUFFER_SIZE                 64
#define EMVIEW_FRAME_SIZE           3
#define EMVIEW_START_OF_NODE_ID     1
#define EMVIEW_START_OF_TEMP        2
#define REPORT_INTERVAL 0xfffff  //0x1 ~ 0xffff ffff, and 0xfffff is about 3 second
//#define REPORT_INTERVAL 0xfff
#define REPORT_LEN  6
#define REPORT_NODEID_INDEX   0
#define REPORT_TEMP_INDEX     2
#define REPORT_HUM_INDEX      4
int32u  readyToSendCoordInfo = REPORT_INTERVAL;
uint8_t TxCounter = 0;
uint8_t sendBuffer[EMVIEW_FRAME_SIZE];
static EmberNetworkStatus networkState = EMBER_NO_NETWORK;
EmberNetworkParameters networkParams;
EmberNodeType nodeType;
//extern ButtonStatus K3Status;
boolean button3Press = FALSE;  // for button push (see halButtonIsr)

int8u tmpBuffer[EMVIEW_FRAME_SIZE]=
{
  0xaa,//start
  0x00, 0x00//data
};
/* Private function prototypes -----------------------------------------------*/
static void applicationTick(void);
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
/* Variables -----------------------------------------------------------------*/
/* Define the endpoint (number + description) required for the ezspUtilInit()
 function */
int8u emberEndpointCount = 1;
EmberEndpointDescription endpointDescription = { PROFILE_ID, 0, };
EmberEndpoint emberEndpoints[] = {
  { ENDPOINT, &endpointDescription },
};
int8u extendedPanId[EXTENDED_PAN_ID_SIZE] = APP_EXTENDED_PANID;
void sendFrame(uint8_t nodeId, uint8_t temperature);
void RCC_Configuration(void);
void GPIO_Configuration(void);

/* Functions -----------------------------------------------------------------*/
/* light application main function */
int main()
{
   EmberStatus status;
   EzspStatus stat;
#ifdef DEBUG
   debug();
#endif
  
   /* configure system clocks (when needed) */
   CLK_Configuration();
  
   /* Init the interrupt */
   Interrupt_Init();
 
   /* init the buttons */
   halInternalInitButton();
  
   /* init leds */ 
   halInternalInitLed(); 
 
   /* Initialize the serial protocol interface SPI */
   hal260SerialInit();
   
   /* Enable external interrupt */
   Interrupt_Enable_EXT_INT(ENABLE);
  
   /* Enable Interrupt */  
   Interrupt_Enable(ENABLE);
    /* System Clocks Configuration */
  RCC_Configuration();
      
  /* NVIC configuration */
  //NVIC_Configuration();

   STM3210C_LCD_Init();
    /* Clear the LCD */
   LCD_Clear(White);
    /* Set the LCD Text Color */
   LCD_SetTextColor(Black);
   printf("   light-switch  \n");
   
   stat = ezspInit();
   status = ezspUtilInit(APP_SERIAL, RESET_UNKNOWN);
 
   // Bring the network up.
   networkParams.panId = APP_PANID; 
   networkParams.radioTxPower = APP_POWER;
   networkParams.radioChannel = APP_CHANNEL;
   MEMCOPY(networkParams.extendedPanId,
           extendedPanId,
           EXTENDED_PAN_ID_SIZE);
   status = emberFormNetwork(&networkParams);
 
 /* USARTy and USARTz configuration ------------------------------------------------------*/
  /* USARTy and USARTz configured as follow:
        - BaudRate = 9600 baud 
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
  USART_InitStructure.USART_BaudRate = 9600;
  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(USARTy, &USART_InitStructure);
   /* Configure the GPIO ports */
  GPIO_Configuration();
 
 
  /* Enable the USARTy */
  USART_Cmd(USARTy, ENABLE);//启动串口
 
 
 
}
/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
  /* Setup the microcontroller system. Initialize the Embedded Flash Interface, 
     initialize the PLL and update the SystemFrequency variable. */
  SystemInit();
   
  /* Enable GPIO clock */
  RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
#ifndef USE_STM3210C_EVAL
  /* Enable USARTy Clock */
  RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE);
#else
  /* Enable USARTy Clock */
  RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE);
#endif
   
}
/**
  * @brief  Configures the different GPIO ports.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
#ifdef USE_STM3210C_EVAL
  /* Enable the USART2 Pins Software Remapping */   //重映射管脚
  GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); 
#elif defined USE_STM3210B_EVAL
  /* Enable the USART2 Pins Software Remapping */
  GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
#endif
 
  /* Configure USARTy Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;//指定初始化的引脚位
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//设置GPIO模式 普通输入模式(浮空)
  GPIO_Init(USARTy_GPIO, &GPIO_InitStructure); //利用PIO_InitStructure来初始化GPIO
 
 
 
  /* Configure USARTy Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用功能的开漏输出模式 值为0x1C
  GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
   USART_HalfDuplexCmd(USARTy, ENABLE); //半双工模式
   while(1)
   {
     emberTick();
    if( --readyToSendCoordInfo == 0)
   {
   sendFrame(0x02,0x23);
   }
  
   if (button3Press) {
  
      button3Press = FALSE;
  
      /* turn allow join on */
      emberPermitJoining(0xff);
      //turn on the lED_LD2 to show permit_join now
      halSetLed(LED_LD2);
   printf("permit node join \n");}
  
   } 
} // end main()
 
void ezspIncomingMessageHandler(EmberIncomingMessageType type,
                                EmberApsFrame *apsFrame,
                                int8u lastHopLqi,
                                int8s lastHopRssi,
                                EmberNodeId sender,
                                int8u bindingTableIndex,
                                int8u addressTableIndex,
                                int8u length,
                                int8u *message)
                               

 
}

void sendFrame(uint8_t nodeId, uint8_t temperature)
{ uint8_t i,sendBufferSize;
  sendBuffer[0] = tmpBuffer[0];
 tmpBuffer[EMVIEW_START_OF_NODE_ID] = nodeId;
 tmpBuffer[EMVIEW_START_OF_TEMP] = temperature;
 
  {for(i = 1, sendBufferSize = 1; i < EMVIEW_FRAME_SIZE ; i++)
   sendBuffer[sendBufferSize++] = tmpBuffer;
   }
TxCounter=0;
    while(TxCounter < sendBufferSize)
 {
     /* Send one byte from USART1 */
     USART_SendData(USARTy, sendBuffer[TxCounter++]);
   
     /* Loop until USART1 DR register is empty */
     while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET);
  {}
 }
}
收藏 评论0 发布时间:2013-3-28 21:58

举报

0个回答

所属标签

相似问题

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版