1386 views|1 replies

1w

Posts

16

Resources
The OP
 

[AT32WB415 Review] 4. Add 3,4 commands to control LED3 [Copy link]

Actually, this function should have been implemented in yesterday's post, but I went astray. I always wanted to use the existing functions to implement it. After reading the posts of forum friends, I realized that the MCU part is the same, but I defined two fewer macros for the BLE part: https://bbs.eeworld.com.cn/thread-1214354-1-1.html

Now let me talk about my implementation:

1. Microcontroller part:

at_cmd.h adds four macros:

#define AT_CMD_IO_SET_2                  "AT+IOSET2\r\n"
#define AT_CMD_IO_SET_3                  "AT+IOSET3\r\n" 

#define AT_CMD_IOSET2                     (0x03)
#define AT_CMD_IOSET3                     (0x04)

Add corresponding definitions and function processing in main.c:


struct at_cmd_msg at_cmd_list[] =
{
  {AT_CMD_IO_SET_LOW, AT_CMD_IOSET0},
  {AT_CMD_IO_SET_HIGH, AT_CMD_IOSET1},
  {AT_CMD_IO_GET,  AT_CMD_IOGET},
	{AT_CMD_IO_SET_2,  AT_CMD_IOSET2},
	{AT_CMD_IO_SET_3,  AT_CMD_IOSET3},
	
};




switch(at_cmd_list[msg_id].msg_id)
      {
        case AT_CMD_IOSET0:
        {
          at32_led_off(LED2);
          at_cmd_send(AT_RESULT_OK0);
          break;
        }
        case AT_CMD_IOSET1:
        {
          at32_led_on(LED2);
          at_cmd_send(AT_RESULT_OK1);
          break;
        }
        case AT_CMD_IOGET:
        {
          if(gpio_output_data_bit_read(GPIOB, GPIO_PINS_7))
          {
            at_cmd_send(AT_RESULT_OK1);
          }
          else
          {
            at_cmd_send(AT_RESULT_OK0);
          }
          break;
        }
				case AT_CMD_IOSET2:
				{
					 at32_led_on(LED3);
					 break;
				}
				case AT_CMD_IOSET3:
				{
					 at32_led_off(LED3);
					 break;
				}
        default:
        {
          at_cmd_send(AT_RSP_ERROR);
          break;
        }
      }          
    recv_cmp_flag = RESET;
    memset(recv_data, 0, strlen(recv_data));

2. BLE part

app.h:

#define AT_CMD_IO_SET_2                  "AT+IOSET2\r\n"
#define AT_CMD_IO_SET_3                  "AT+IOSET3\r\n" 

custom_task.c:

Add two send commands:

static int gattc_write_req_ind_handler(ke_msg_id_t const msgid, struct gattc_write_req_ind const *param,
                                      ke_task_id_t const dest_id, ke_task_id_t const src_id)
{
    struct gattc_write_cfm * cfm;
    uint8_t status = GAP_ERR_NO_ERROR;
    //Send AT command
    if(uart_tp_mode_flag == false)
    {
      switch(param->value[0])
			{
				case 0:
				case 1:
			UART_SEND_DATA(AT_CMD_IO_SET, param->value[0]);
				break;
				case 3:
					UART_SEND_DATA(AT_CMD_IO_SET_2, param->value[0]);
					break;
				case 4:
					UART_SEND_DATA(AT_CMD_IO_SET_3, param->value[0]);
			}
    }
  
    cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm);
    cfm->handle = param->handle;
    cfm->status = status;
    ke_msg_send(cfm);
  
    return (KE_MSG_CONSUMED);
}

When compiling BLE, I encountered a prompt that the command prompt has been disabled by the administrator, and the BIN file I want to burn cannot be generated.

I followed: https://www.dadighost.com/help/dnjc/7450.html

Solved.

After powering on again, the long-lost LED3 lights up, but of course it goes out again after sending 0x04.

This post is from RF/Wirelessly

Latest reply

It turns out that two macros were missing. Just solve it   Details Published on 2022-8-19 07:29
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 

6593

Posts

0

Resources
2
 

It turns out that two macros were missing.

Just solve it

This post is from RF/Wirelessly
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

快速回复 返回顶部 Return list