项目
关于
适用于 STM32 的 AT 命令解析器
开发工具可以做什么
- Event-driven UART handling with DMA support.
- Optional RTOS compatibility (FreeRTOS, ThreadX).
- Debug logging when enabled.
- AT command slave mode with custom handlers.
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文AT Command Library for STM32
Please Do not Forget to get STAR, DONATE and support me on social networks. Thank you. :sparkling_heart:
- Author: Nima Askari
- Github: https://www.github.com/NimaLTD
- Youtube: https://www.youtube.com/@nimaltd
- LinkedIn: https://www.linkedin.com/in/nimaltd
- Instagram: https://instagram.com/github.NimaLTD
Overview
The AT Command Library (ATC) simplifies UART communication for STM32 microcontrollers with an event-driven approach and debug capabilities. This updated version introduces AT command slave functionality, allowing the STM32 to process commands like AT+LED=ON and respond (e.g., +OK), making it ideal for IoT and embedded applications.
Key Features
- Event-driven UART handling with DMA support.
- Optional RTOS compatibility (FreeRTOS, ThreadX).
- Debug logging when enabled.
- AT command slave mode with custom handlers.
Installation
- Download the library: NimaLTD.I-CUBE-ATC.pdsc.
- Import it into STM32CubeMX and enable it.
- Configure UART:
- Enable UART interrupt.
- Enable TX/RX DMA in Normal Mode.
- In the Code Generator tab, select "Generate peripheral initialization as a pair of .c/.h files per peripheral."
- Generate the project code.
Getting Started
- Declare an
ATC_HandleTypeDefstructure in your code. - Add
ATC_IdleLineCallback()to the UART idle line callback (e.g., inHAL_UARTEx_RxEventCallback). - Initialize the library with
ATC_Init(). - Optionally, set up events with
ATC_SetEvents()or AT commands withATC_SetCommands(). - Call
ATC_Loop()in your main loop to process incoming data.
Using AT Command Handlers
This library now supports AT command handling, enabling the STM32 to act as a command slave. Send commands like AT+LED=ON from an external device, and the STM32 will execute them and respond (e.g., +OK or +LED:ON).
Setup Steps
- Define Command Handlers: Create functions to process commands and generate responses.
- Create a Command Table: Use
ATC_CmdTypeDefto map command prefixes (e.g.,AT+LED=) to handlers. - Register Commands: Call
ATC_SetCommands()to link the table to your ATC handle. - Run the Loop: Use
ATC_Loop()to handle incoming commands and events.
Example: LED Control
Control an LED and query its state via AT commands:
#include "atc.h"
// ATC handle
ATC_HandleTypeDef hAtc;
// Command handler for setting LED state
void Handle_LED(const char* args, char* response)
{
if (strcmp(args, "ON") == 0)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); // Adjust port/pin
strcpy(response, "+OK");
}
else if (strcmp(args, "OFF") == 0)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
strcpy(response, "+OK");
}
else
{
strcpy(response, "+ERROR");
}
}
// Command handler for querying LED state
void Handle_GetLED(const char* args, char* response)
{
GPIO_PinState led_state = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_5);
strcpy(response, (led_state == GPIO_PIN_SET) ? "+LED:ON" : "+LED:OFF");
}
// Command table
ATC_CmdTypeDef at_commands[] =
{
{"AT+LED?", Handle_GetLED}, // Query LED state: "AT+LED?" -> "+LED:ON"
{"AT+LED=", Handle_LED}, // Set LED state: "AT+LED=ON" -> "+OK"
{NULL, NULL} // Terminator
};
// UART handle (from STM32CubeMX)
extern UART_HandleTypeDef huart1;
int main(void)
{
// HAL initialization (from STM32CubeMX)
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_USART1_UART_Init();
// Initialize ATC
ATC_Init(&hAtc, &huart1, 256, "Slave1");
// Register AT commands
ATC_SetCommands(&hAtc, at_commands);
while (1)
{
ATC_Loop(&hAtc); // Process commands and events
}
}
// Add to your UART IRQ handler (e.g., stm32f1xx_it.c)
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) {
if (huart->Instance == USART1)
{ // Adjust for your UART instance
ATC_IdleLineCallback(&hAtc, Size);
}
}
Command Responses
AT+LED=ON→+OK(turns LED on)AT+LED=OFF→+OK(turns LED off)AT+LED?→+LED:ONor+LED:OFF(queries state)- Unknown command →
+ERROR
Watch the Video:
The old Version: https://github.com/nimaltd/ATC/archive/refs/tags/3.0.3.zip
探索相关项目
加载中…
