主函数;
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "arduino.h"
//ALIENTEK Mini STM32¿a·¢°å·¶ày′úÂë3
//′®¿úêμÑé
//¼¼êõÖ§3Ö£o
www.openedv.com
//1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾
int main(void)
{
u8 t;
u8 len;
u16 times=0;
u8 ax;
u8 bx='*'; //*μÄêμ¼êÖμÆäêμ′ú±í0x42ò2¾íêÇASCIIμÄÖμêÇ42
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// éèÖÃÖD¶ÏóÅÏ輶·Ö×é
uart_init(9600); //′®¿ú3õê¼»ˉÎa9600
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
USART3_Config();
while(1)
{
delay_ms(100);
LED0=!LED0;
//GPIO_ResetBits(GPIOA,GPIO_Pin_8);
LED1=0;
ax=arduino_Analysis();
printf("sudo=%d
",sudu);
printf("a=%d
",ax);
//printf("%d
",bx);
//delay_ms(1000);
//////////////////////////////////Ô-oˉêy
// LED0=!LED0;
// if(USART_RX_STA&0x8000)
// {
// len=USART_RX_STA&0x3fff;//μÃμ½′Ë′νóêÕμ½μÄêy¾Y3¤¶è
// printf("
Äú·¢ËíμÄÏûÏ¢Îa:
");
// for(t=0;t<len;t++)
// {
// USART1->DR=USART_RX_BUF[t];
// while((USART1->SR&0X40)==0);//μè′y·¢Ëí½áêø
// }
// printf("
");//2åèë»»DD
// USART_RX_STA=0;
// }else
// {
// times++;
// if(times%5000==0)
// {
// printf("
ALIENTEK MiniSTM32¿a·¢°å ′®¿úêμÑé
");
// printf("ÕyμãÔ-×ó@ALIENTEK
");
// }
// if(times%200==0)printf("Çëêäèëêy¾Y,òÔ»Ø3μ¼ü½áêø
");
// //éá˸LED,ìáê¾Ïμí3ÕyÔúÔËDD.
// delay_ms(10);
// //}
// }
}
}
arduino.c函数
#include "arduino.h"
u8 Arduino_sudo;
u8 Arduino_jiaodu;
u8 sudu;
u8 jiaodu;
u8 x=7;
u8 USART3_RX_BUF[USART_REC_LEN]; //½óêÕ»o3å,×î′óUSART_REC_LEN¸ö×Ö½ú.
//½óêÕ×′ì¬
u8 Arduino_Receive_Data[11];
u8 Arduino_receive_counter=0;
u8 Arduino_receive_flag=0;
u8 Arduino_receive_temp[10]={0x42,0x39,0x49,0x39,0x45,0x39,0x49,0x54,0x39,0X39};
//u8 res[8];
//bit15£¬ ½óêÕíê3é±êÖ¾
//bit14£¬ ½óêÕμ½0x0d
//bit13~0£¬ ½óêÕμ½μÄóDD§×Ö½úêyÄ¿
u16 USART3_RX_STA=0; //½óêÕ×′쬱ê¼Ç
void USART3_Config(void) //ᬽóêy′«μçì¨ 3õê¼»ˉ ÅäÖÃUSART2
{
GPIO_InitTypeDef GPIO_InitStructure; //′®¿ú¶Ë¿úÅäÖýá11ìå±äá¿
USART_InitTypeDef USART_InitStructure; //′®¿ú2ÎêyÅäÖýá11ìå±äá¿
NVIC_InitTypeDef NVIC_InitStructure;
//μú12½£o′ò¿aGPIOoíUSART2¿¼tμÄê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //′ò¿aGPIOAê±ÖóoíGPIOA¸′óÃê±Öó
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //′ò¿a′®¿ú¸′óÃê±Öó
USART_DeInit(USART3); //¸′λ′®¿ú1
//μú22½£o½«USART2 Tx£¨·¢Ëí½Å£©μÄGPIOÅäÖÃÎaíÆíì¸′óÃÄ£ê½
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //′®¿ú2·¢Ëí½Å
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //êä3öËù¶è50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //3õê¼»ˉGPIOA
//μú32½£o½«USART2 Rx£¨½óêսţ©μÄGPIOÅäÖÃÎa¸¡¿ÕêäèëÄ£ê½
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //′®¿ú2½óêÕ½Å
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿Õêäèë
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //éÏà-êäèë
GPIO_Init(GPIOB, &GPIO_InitStructure); //3õê¼»ˉGPIOA
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ; //ÇàÕ¼óÅÏ輶 3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //×óóÅÏ輶 3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ í¨μàê1Äü
NVIC_Init(&NVIC_InitStructure); //ÖD¶ÏóÅÏ輶3õê¼»ˉ
//μú42½£oÅäÖÃUSART12Îêy
USART_InitStructure.USART_BaudRate = 115200; //2¨ìØÂêéèÖão57600
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //êy¾YλêyéèÖão8λ
USART_InitStructure.USART_StopBits = USART_StopBits_1; //í£Ö1λéèÖão1λ
USART_InitStructure.USART_Parity = USART_Parity_No; //êÇ·ñÆæżD£Ñé£oÎT
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //ó2¼tá÷¿ØÖÆÄ£ê½éèÖãoûóDê1Äü
USART_InitStructure.USART_Mode = USART_Mode_Rx ;//| USART_Mode_Tx; //½óêÕóë·¢Ëí¶¼ê1Äü
USART_Init(USART3, &USART_InitStructure); //3õê¼»ˉUSART2
//′ò¿a·¢ËíÖD¶Ïoí½óêÕÖD¶Ï(èç1ûDèòaÖD¶Ï)
// USART_ITConfig(USART2, USART_IT_TXE, ENABLE); // ê1ÄüÖ¸¶¨μÄUSART1·¢ËíÖD¶Ï £»
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); // ê1ÄüÖ¸¶¨μÄUSART1½óêÕÖD¶Ï £»
//μú52½£oê1Äü USART2£¬ ÅäÖÃíê±Ï
USART_Cmd(USART3, ENABLE); //ê1Äü USART2
//èçÏÂóï¾ä½a¾öμú1¸ö×Ö½úÎT·¨Õyè··¢Ëí3öè¥μÄÎêìa
USART_ClearFlag(USART3, USART_FLAG_TC); //Çå′®¿ú2·¢Ëí±êÖ¾
}
void USART3_IRQHandler(void) //′®¿ú3ÖD¶Ï·tÎñ3ìDò
{
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //½óêÕÖD¶ÏóDD§,èô½óêÕêy¾Y¼Ä′æÆ÷Âú
{
Arduino_Receive_Data[Arduino_receive_counter]=USART_ReceiveData(USART3);
if(Arduino_receive_counter==0&& Arduino_Receive_Data[0]!='*') return ;/////87=W ê×Ö¡
Arduino_receive_counter++;
if(Arduino_receive_counter==10)
{
Arduino_receive_counter=0;
Arduino_receive_flag=1;
}
}
}
u8 arduino_Analysis(void)
{
if(Arduino_receive_flag==1)
{
Arduino_receive_flag=0;
memcpy(Arduino_receive_temp,Arduino_Receive_Data,10);
// printf("0=%d
",Arduino_receive_temp[0]);
// printf("1=%d
",Arduino_receive_temp[1]);
// printf("2=%d
",Arduino_receive_temp[2]);
// printf("3=%d
",Arduino_receive_temp[3]);
// printf("4=%d
",Arduino_receive_temp[4]);
// printf("5=%d
",Arduino_receive_temp[5]);
// printf("6=%d
",Arduino_receive_temp[6]);
// printf("7=%d
",Arduino_receive_temp[7]);
// printf("8=%d
",Arduino_receive_temp[8]);
// printf("8=%d
",x);
}
//Res =Arduino_Receive_Data[Arduino_receive_counter]; //¶á衽óêÕμ½μÄêy¾Y
return Arduino_receive_temp[1];
sudu=Arduino_receive_temp[7];
}
arduino.h函数如下
#ifndef _ARDUINO_H
#define _ARDUINO_H
#include "stdio.h"
#include "usart.h"
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
#include "string.h"
#include "sys.h"
void USART3_Config(void);
//void USART3_IRQHandler(void);
//void TIM4_Init(u16 arr,u16 psc);
//void TIM4_IRQHandler(void);
void TIM4_Init(u16 arr,u16 psc);
u8 arduino_Analysis(void);
#define USART3_REC_LEN 200 //¶¨òå×î′ó½óêÕ×Ö½úêy 200
#define EN_USART3_RX 1 //ê1Äü£¨1£©/½ûÖ1£¨0£©′®¿ú1½óêÕ
extern u8 sudu;
//èç1ûÏë′®¿úÖD¶Ï½óêÕ£¬Çë2»òa×¢êíòÔÏÂo궨òå
#endif
有没有大神指导到底是怎么回事,一直找不到什么原因
一周热门 更多>