在线时间1 小时
UID422049
ST金币0
蝴蝶豆0
注册时间2013-3-19
新手上路
- 最后登录
- 2019-6-3
|
a0a.1 0b0c
一开始用中断通信,能够成功,但是用每次复位下,才能发送数据,所以想选择查询方式,就去掉了中断配置,其他的串口通信的配置留下,然后
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);
{}
}
} |
|