Browse Source

main中调试urat1通信正常

master
zhuang 4 years ago
parent
commit
fa8b98f748
  1. 7
      README.md
  2. 167
      app.c
  3. 2
      basic_type.h
  4. BIN
      es7p_project_test.suo
  5. 49
      lcd.c
  6. 2
      lcd.h
  7. 18
      led.c
  8. 6
      led.h
  9. 16
      system_init.c
  10. 110
      t21_t8.c
  11. 1
      t21_t8.h
  12. 48
      uart.c

7
README.md

@ -31,3 +31,10 @@
[建议阅读避免踩坑](./doc/问题积累.md)
```
第一步:接收屏幕串口数据正常,打断点的形式,拿到buff里面的命令数据,
第一步:测试两个串口通信正常,
第二步:
```

167
app.c

@ -9,131 +9,6 @@
*
*/
#include "app.h"
extern volatile int32_t lcd_issue_motor_speed;//lcd下发的速度单位dsp
extern volatile int32_t speed_dsp_now;//dsp
extern int16_t motor_off_state;//
extern volatile int16_t judge_now_foreward_or_reversal_state;//
extern int32_t wait_send_to_motor_time1s;//
extern int32_t first_set_speed_state; //
extern volatile int32_t recv_lcd_data_state=0;//10
extern volatile int32_t recv_motor_data_state=0;//10
void func(void)
{
volatile unsigned char str[] = "speed-1000";
send_cmd_to_motor(str,10); //
}
void global_state_inquire(void)
{
/**
* @brief
*
*/
motor_jerk_status();//
//inquire_motor_error_state();//1.5
if(motor_off_state)//
{
motor_off_state=0;
judge_now_foreward_or_reversal_state=0;//
first_set_speed_state=0;//
}
if(recv_lcd_data_state)
{
data_from_lcd_recv_Ok(); //lcd的数据是否完成
}
if(recv_motor_data_state)
{
data_from_motor_recv_Ok(); //
}
}
/**
void main()
{
peripheral_config();
//start_up(); //
//func();
int32_t nowexpectspeed_main=0;
int32_t setspeedthistime_main=0;
while (1)
{
global_state_inquire();
if(lcd_issue_motor_speed!=speed_dsp_now)
{
if(lcd_issue_motor_speed>speed_dsp_now&&wait_send_to_motor_time1s>1100)//8000
//if(lcd_issue_motor_speed>speed_dsp_now)
{
wait_send_to_motor_time1s=0;//
nowexpectspeed_main = speed_dsp_now + 100;
if (nowexpectspeed_main > lcd_issue_motor_speed) {
nowexpectspeed_main = lcd_issue_motor_speed;
}
set_moter_speed_internal(nowexpectspeed_main);// 10
//sleep_ms(500);
}
else if(lcd_issue_motor_speed<speed_dsp_now&&wait_send_to_motor_time1s>1100)//0 //550 600
//else if(lcd_issue_motor_speed<speed_dsp_now)
{
wait_send_to_motor_time1s=0;//
setspeedthistime_main = speed_dsp_now - 100;
if (setspeedthistime_main < lcd_issue_motor_speed) {
setspeedthistime_main = lcd_issue_motor_speed;
}
set_moter_speed_internal(setspeedthistime_main);
//sleep_ms(500);
}
}
}
}
*/
void peripheral_config_list(void)
{
/**
* @brief
*
*/
sys_init();
led_config();
beep_config();
lcd_uart_config();
motor_uart_config();
jerk_key_config();
t21_config();
init_timer1_as_ticketustimer_in32M();
}
void send_cmd_to_motor_list(volatile char buff[20], unsigned int num) {
/**
* @brief
* @param buff
*/
uint16_t count = 1200;
rs485_re_port |= (0x01 << 3);
while (num--) {
while (!TRMT0)
;
TX0B = *buff;
buff++;
}
while (!TRMT0)
; //
rs485_re_port &= ~(0x01 << 3);
}
void main()
{
volatile unsigned char str[] = "speed-1000";
peripheral_config_list();
send_cmd_to_motor_list(str,10); //
while (1)
{
send_cmd_to_motor_list(str,10);
}
}
void peripheral_config(void)
{
/**
@ -146,7 +21,6 @@ void peripheral_config(void)
lcd_uart_config();
motor_uart_config();
jerk_key_config();
t21_config();
init_timer1_as_ticketustimer_in32M();
}
@ -167,4 +41,43 @@ void start_up(void)
led_off;
beep_on;
}
}
}
extern volatile char lcd_rxbuff[50] = {0};
extern volatile int32_t lcd_count = 0;
extern uint8_t g_lcd_rxbuf_isready;//lcd数据接收过程中为真
uint32_t judge_recv_lcd_data_finish_main(uint8_t time)
{
/**
* @brief LCD的数据完成
*/
static uint32_t recv_lcd_data_time = 0;
recv_lcd_data_time = time;
if(recv_lcd_data_time=0)
{
recv_lcd_data_time = hal_get_ticket();
return recv_lcd_data_time;
}
else if (hal_has_passedms(recv_lcd_data_time) > 10) {
g_lcd_rxbuf_isready=false;
recv_lcd_data_time = hal_get_ticket();
send_cmd_to_lcd(lcd_rxbuff,lcd_count);//
lcd_count=0;
}
}
void main()
{
peripheral_config();//ram清零
uint8_t record_last_time=0;
while (1)
{
debug_light_ctrl_process_in_main_loop();//
if(g_lcd_rxbuf_isready)//
{
record_last_time = judge_recv_lcd_data_finish_main(record_last_time);
}
}
}

2
basic_type.h

@ -28,7 +28,7 @@ typedef int int16_t;
typedef unsigned int uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
//typedef unsigned char bool;
#define false 0
#define true 1
#define NULL 0

BIN
es7p_project_test.suo

49
lcd.c

@ -11,9 +11,9 @@
#include "lcd.h"
volatile char lcd_rxbuff[50] = {0};
volatile int32_t lcd_count = 0;
volatile int32_t recv_lcd_data_state=0;//10
volatile int32_t from_lcd_recv_state = 0;
volatile int32_t lcd_t8_state = 0;
//volatile int32_t recv_lcd_data_state=0;//10
//volatile int32_t from_lcd_recv_state = 0;
//volatile int32_t lcd_t8_state = 0;
extern volatile int32_t first_set_motor_speed_dsp;
volatile int32_t lcd_issue_motor_speed=0;
volatile int16_t judge_now_foreward_or_reversal_state=0;//01
@ -21,6 +21,11 @@ volatile int32_t first_set_speed_state=0;
extern volatile int32_t speed_dsp_now;//dsp
extern int32_t recv_lcd_data_time;
extern volatile int32_t motor_jerk_state;//1
//-----------------------------------------
//-----------------------------------------
void lcd_uart_config(void)
{
/**
@ -44,46 +49,30 @@ void send_cmd_to_lcd(volatile char buff[20], unsigned int num)
buff++;
}
}
//---------------------------------------
//---------------------------------------
uint8_t g_lcd_rxbuf_isready = 0;
static uint32_t process_recv_lcd_data_time = 0;
void recv_from_lcd_data(unsigned char data)
{
/**
* @brief lcd的数据
*
*/
recv_lcd_data_state=1;
recv_lcd_data_time=0;
g_lcd_rxbuf_isready=true;//
lcd_rxbuff[lcd_count++] = data;
}
void data_from_lcd_recv_Ok(void)
void judge_recv_lcd_data_finish(void)
{
/**
* @brief LCD的数据完成
*/
if(recv_lcd_data_time>20)
{
send_cmd_to_lcd(lcd_rxbuff,lcd_count);
send_cmd_to_motor(lcd_rxbuff, lcd_count);
if(motor_jerk_state==1&&lcd_rxbuff[4]==0x50&&lcd_rxbuff[5]==0x20)//
{
send_cmd_to_lcd(lcd_rxbuff,lcd_count);
lcd_switch_anomaly_page();//
sleep_ms(3000);
lcd_switch_anomaly_page_key();
lcd_count = 0;
recv_lcd_data_state=0;
}
else
{
//send_cmd_to_motor(lcd_rxbuff, lcd_count);
lcd_data_analyse(lcd_rxbuff, lcd_count);
//send_cmd_to_lcd(lcd_rxbuff,lcd_count);//2
//send_cmd_to_motor(motor_rxbuff, motor_Count); //1
lcd_count = 0;
recv_lcd_data_state=0;
}
static uint32_t recv_lcd_data_time = 0;
if (hal_has_passedms(recv_lcd_data_time) > 10) {
g_lcd_rxbuf_isready=false;
recv_lcd_data_time = hal_get_ticket();
send_cmd_to_lcd(lcd_rxbuff,lcd_count);//
}
}

2
lcd.h

@ -10,7 +10,7 @@
void lcd_uart_config(void);
void lcd_send_commands(void);
void send_cmd_to_lcd(volatile char buff[20],unsigned int num);
void data_from_lcd_recv_Ok(void);
void judge_recv_lcd_data_finish(void);
uint8_t lcd_data_analyse(volatile char buff[20], unsigned int num);
void recv_from_lcd_data(unsigned char data);
void lcd_switch_anomaly_page(void);

18
led.c

@ -29,3 +29,21 @@ void beep_config(void)
beep_port &= ~(0x01 << 0); //
}
void debug_light_ctrl_process_in_main_loop() {
/**
* @brief 300ms
*
*/
static uint32_t last_ctrl_light_ticket = 0;
uint16_t flicker_period = configDebugLightFlipPeriodMS;
if (hal_has_passedms(last_ctrl_light_ticket) > flicker_period) {
static uint8_t debuglight_state = false;
DEBUG_LIGHT_IO() = debuglight_state;
debuglight_state = !debuglight_state;
last_ctrl_light_ticket = hal_get_ticket();
}
}

6
led.h

@ -5,6 +5,10 @@
#include "hic.h"
#include "basic_type.h"
#include "io_config.h"
#include "t21_t8.h"
#define configDebugLightFlipPeriodMS 300
#define DEBUG_LIGHT_IO() PB4
#define led_on debug_led_port &=~(0x01<<4)
#define led_off debug_led_port |=(0x01<<4)
@ -15,5 +19,5 @@
void led_config(void);
void beep_config(void);
void jerk_key_config(void);
void start_up(void);
void debug_light_ctrl_process_in_main_loop();
#endif

16
system_init.c

@ -18,8 +18,6 @@ extern volatile int32_t speed_dsp_now;//当前电机的速度单位dsp
extern volatile int32_t motor_jerk_state;
extern volatile char lcd_rxbuff[50];
extern volatile int32_t lcd_count;
extern volatile int32_t from_lcd_recv_state;
extern volatile int32_t lcd_t8_state;
extern volatile int16_t judge_now_foreward_or_reversal_state;
void ram_clear(void)
{
@ -62,14 +60,22 @@ void clear_global_variable(void)
motor_jerk_state= 0;
lcd_rxbuff[50]= 0;
lcd_count= 0;
from_lcd_recv_state= 0;
lcd_t8_state= 0;
judge_now_foreward_or_reversal_state=0;
}
void set_gie(uint8_t state) {
/**
* @brief :ES7P169C_Datasheet_C%20V1.3.pdf:7.5.1
*/
while (GIE != state) {
GIE = state;
}
}
void sys_init(void)
{
ram_clear();
clear_global_variable();
//clear_global_variable();
gpio_Init();
set_gie(1);
}

110
t21_t8.c

@ -2,27 +2,40 @@
#include "led.h"
volatile unsigned char timer_cnt;
extern volatile int motor_jerk_state;
volatile uint32_t g_ticket100us = 0;
void t21_config(void)
{
/**
* @brief T21 LED的状态
*
*/
T21CL = 0x00; //
T21CM = 0x0F; //1:16
T21CH = 0x79; //121
T21PH = 0x0F; //4
T21PL = 0xFF; //8
T21VIE = 1; //T21溢出中断
T21VIF = 0; //
GIE = 1; //
T21EN = 1; //使T21
}
int32_t wait_send_to_motor_time1s=0;
int32_t recv_motor_data_time=0;
int32_t recv_lcd_data_time=0;
int32_t inquire_error_time=0;
volatile uint32_t g_ticket100us = 0;//
/**
* @brief 32M的情况下初始化时钟1作为ticket源
*
*/
void init_timer1_as_ticketustimer_in32M() {
// T11M
/**
* @brief
* 1ms一次中断
* T11CM = 0x0f 16 = 2MHZ
* T11CH = 0 0
* T11PH T11PL = 200 //100us
* T11PH = 0x07
* T11PL = 0xD0
*/
T11CL = 0x00; //
T11CM = 0x0F; //1:16 //1:16
T11CH = 0x00; //0+1
static_assert(configTicketUs <= 10000 && configTicketUs >= 100);
uint16_t count = 2000 / 1000 * configTicketUs;
T11PH = count >> 8; //8
T11PL = count & 0xFF; // 200
T11VIE = 1; //T11溢出中断
T11VIF = 0; //
T11EN = 1; //使T11
}
int32_t clear_time()
{
if(wait_send_to_motor_time1s>=UINT32_MAX)
@ -46,6 +59,25 @@ int32_t clear_time()
inquire_error_time=0;
}
}
uint32_t hal_has_passed_ticket(uint32_t lastticket) {
uint32_t now = g_ticket100us;
if (now >= lastticket) {
return now - lastticket;
} else {
return UINT32_MAX - lastticket + now;
}
}
uint32_t hal_has_passedms(uint32_t lastticket) {
/**
* ticket的数值进行修改.
*/
static_assert(configTicketUs == 1000);
return hal_has_passed_ticket(lastticket);
}
int32_t hal_get_ticket()
{
return g_ticket100us;
@ -71,34 +103,7 @@ void hal_ticket_inc()
recv_lcd_data_time++;
inquire_error_time++;
}
volatile uint32_t g_ticket100us = 0;
/**
* @brief 32M的情况下初始化时钟1作为ticket源
*
*/
void init_timer1_as_ticketustimer_in32M() {
// T11M
/**
* @brief
* 1ms一次中断
* T11CM = 0x0f 16 = 2MHZ
* T11CH = 0 0
* T11PH T11PL = 200 //100us
* T11PH = 0x07
* T11PL = 0xD0
*/
T11CL = 0x00; //
T11CM = 0x0F; //1:16 //1:16
T11CH = 0x00; //0+1
static_assert(configTicketUs <= 10000 && configTicketUs >= 100);
uint16_t count = 2000 / 1000 * configTicketUs;
T11PH = count >> 8; //8
T11PL = count & 0xFF; // 200
T11VIE = 1; //T11溢出中断
T11VIF = 0; //
T11EN = 1; //使T11
}
void system_module_process_interrupt() {
/**
@ -111,20 +116,3 @@ void system_module_process_interrupt() {
}
}
void t21_irq_interrupt(void)
{
/**
* @brief T21的0.5s的中断服务函数
*
*/
if (T21VIE == 1 && T21VIF == 1) //
{
T21VIF = 0; //
if (motor_jerk_state == 1)
{
PB0 = ~PB0;
}
PB4 = ~PB4;
}
}

1
t21_t8.h

@ -16,5 +16,6 @@ void system_module_process_interrupt();
int32_t sleep_ms(int32_t time);
void init_timer1_as_ticketustimer_in32M();
int32_t hal_get_ticket();
uint32_t hal_has_passedms(uint32_t lastticket);
#endif

48
uart.c

@ -16,14 +16,11 @@
#include "lcd.h"
#if 0
#endif
unsigned char rxbuf;
unsigned char rx485buf;
#define IT_SR //中断发送接收,注释此宏定义则使用查询方式发送接收
#define CLRWDT() \
{ \
__Asm CWDT; \
} //
extern unsigned char rxbuf;
void uart0_config(void)
{
@ -141,10 +138,22 @@ void uart1_irq_interrupt(void)
* @brief 1
*
*/
if (RX1IE == 1 && RX1IF == 1)
if (RX1IE == 1)
{
rxbuf = RX1B;
recv_from_lcd_data(rxbuf);
//
if (FERR1 == 1) {
}
//
if (OERR1 == 1) {
//
RX1EN = 0;
RX1EN = 1;
}
if ( RX1IF == 1)
{
uint8_t rx232data = RX1B;
recv_from_lcd_data(rx232data);
}
}
}
@ -152,18 +161,29 @@ void uart1_irq_interrupt(void)
void isr(void) interrupt
{
/**
* @brief 0
* @brief
*
*/
//uint16_t count = 1200;
if (RX0IE == 1 && RX0IF == 1)
if (RX0IE == 1)
{
//
if (FERR0 == 1) {
}
//
if (OERR0 == 1) {
//
RX0EN = 0;
RX0EN = 1;
}
if ( RX0IF == 1)//0
{
rx485buf = RX0B;
recv_from_motor_data(rx485buf);
uint8_t rx485data = RX0B;
recv_from_motor_data(rx485data);
}
t21_irq_interrupt();
uart1_irq_interrupt();
system_module_process_interrupt();
}
uart1_irq_interrupt();//
system_module_process_interrupt();//
}
#endif

Loading…
Cancel
Save