USB receive when pressed enter
Hello, I am trying to establish a USB communication between PC and a STM32 MCU. I want to receive an integer from a PC. (range of the integer is between 0 and 20.000). I added those lines:
To usb_cdc_if.h :
__weak void CDC_ReceiveCallBack(uint8_t *buf, uint32_t len);To the usb_cdc_if.c
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
CDC_ReceiveCallBack(Buf, Len);
return (USBD_OK);
/* USER CODE END 6 */
}
.
.
.
__weak void CDC_ReceiveCallBack(uint8_t *buf, uint32_t len)
{}And in the main class:
void CDC_ReceiveCallBack(uint8_t *buf, uint32_t len)
{
fan_speed=atoi(buf);
memset(statusString,0x00,255);
statusStringLength = sprintf(statusString,"Fan Speed: %d ", fan_speed);
CDC_Transmit_FS(statusString,statusStringLength);
}So I can only receive 1 digit numbers. Should I add an if statement to the beginning of function and when enter is pressed, then I should receive it from buffer?
