2018-12-19 01:53 AM
im having trouble to send a bytes packet with CDC_Transmit_FS function.
For example:
CDC_Transmit_FS((uint8_t*)SendArray1,512);
Doesnt work for me, it sends garbage
But if i sprintf bytes and send them in a loop, it works perfectly, but it sends data in hex string.
for(i=0;i<512;i++)
{
SendArray1[i] = ByteRead_DataPin(port1);
sprintf(str,"%02X",SendArray1[i]);
CDC_Transmit_FS((uint8_t*)SendArray1,strlen(str));
}
im using default settings from CubeMX:
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
/* USER CODE BEGIN 7 */
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
if (hcdc->TxState != 0){
return USBD_BUSY;
}
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
/* USER CODE END 7 */
return result;
}
So in the end how can i send the bytes packet?
my mcu is stm32f407
also how to properly check that Transmit_FS is ready to send data and it doesnt busy
2018-12-19 12:33 PM
> how to properly check that Transmit_FS is ready to send data and it doesnt busy
You've already found the code:
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
if (hcdc->TxState != 0){
return USBD_BUSY;
}
Try to send by smaller pieces.
-- pa