UART Communication YP-01 Reading Transmitting Data Error - Page 1
Forum section: electronics / general

author: elefurtronik
author_rank: Regular Contributor
timestamp: May 06, 2023, 09:55:46 pm
content: Hello,I am learning embedded programming with STM32F407VGT6 Discovery.I am sending data over UART to my PC. I have a TTL to USB device(YP-01) which is a little bit old(I bought it in ~2015). I installed its driver but when I enter my device manager I see a text that saysPL2303HXA PHASED OUT SINCE 2012. PLEASE CONTACT YOUR SUPPLIER.I use realterm software to read the UART message that I sent over TX(PD5) pin. When I try to open the port, I get Apro exception error.My connections:1.  PD5(TX) ->  RX (I also tried to connect TX to TX and doesn't work either.)2.  5V ->  5V3.  GND ->  GNDWhy doesn't my ttl2usb device work?Code:#include "stm32f407xx.h"#include <stdint.h>#define UART2EN(1U<<17)#define GPIODEN(1U<<3)#define CR1_TE(1U<<3)#define CR1_UE(1U<<13)#define SR_TXE(1U<<7)#define SYS_FREQ16000000#define APB1_CLKSYS_FREQ#define UART_BAUDRATE115200static void UART_set_baudrate(USART_TypeDef *USARTx,uint32_t PeriphClk, uint32_t BaudRate);static uint16_t compute_UART_baudrate(uint32_t PeriphClk, uint32_t BaudRate);void UART2_TX_Init(void);void UART2_write(int ch);int main(void){UART2_TX_Init();while(1){UART2_write('F');}}void UART2_TX_Init(void){/*Enable clock access to GPIOD*/RCC->AHB1ENR |= GPIODEN;/*PD5 -> TX*PD6 -> RX*//*Configure Pin D5 Function Mode to Alternate Function Mode*/GPIOD->MODER &= ~(1U<<10);GPIOD->MODER |= (1U<<11);/*Configure UART_TX Alternate Function Type to UART_TX AF7 */GPIOD->AFR |= (1U<<20);GPIOD->AFR |= (1U<<21);GPIOD->AFR |= (1U<<22);GPIOD->AFR &=~(1U<<23);/*Configure the UART Module*/RCC->APB1ENR |= UART2EN;/*Configure the Baud rate*/UART_set_baudrate(USART2, APB1_CLK, UART_BAUDRATE);/*Configure the transfer direction*/USART2->CR1 = CR1_TE; // To clean all the information in UART, we don't put or(|) operatorUSART2->CR1|= CR1_UE; // Enable the USART}void UART2_write(int ch){while(!(USART2->SR & SR_TXE)){} // We are being sure that the transmit data register is empty.USART2->DR = (ch & 0xFF);}static void UART_set_baudrate(USART_TypeDef *USARTx,uint32_t PeriphClk, uint32_t BaudRate){USARTx->BRR = compute_UART_baudrate(PeriphClk,BaudRate);}static uint16_t compute_UART_baudrate(uint32_t PeriphClk, uint32_t BaudRate){return ((PeriphClk + (BaudRate / 2U))/BaudRate);}

author: Siwastaja
author_rank: Super Contributor
timestamp: May 07, 2023, 07:37:15 am
content: There's no point in looking at the STM32 code if your USB-to-serial (nothing to do with TTL!) adapter is not working. Start by testing the adapter:1) Plug the adapter in, but don't connect TX/RX to anything,2) type some characters in terminal program: nothing should appear on screen3) connect TX and RX together4) type something again. What you type should appear on screenIf this test fails, I think easiest is to buy a new USB-serial adapter.

author: GromBeestje
author_rank: Frequent Contributor
timestamp: May 07, 2023, 08:34:24 am
content: Bit a bit googling gets this for examplehttps://answers.microsoft.com/en-us/windows/forum/all/pl2303hxa-phased-out-since-2012-version-38310/2ef1d8fa-59fc-421e-9510-b1f63c68d4f9Keep in mind, distributing binaries, especially drivers, may contain malware.Also the manufactuers site sayshttps://www.prolific.com.tw/US/ShowProduct.aspx?p_id=223&pcid=126."Windows 8/8.1/10 are NOT supported in PL-2303HXA and PL-2303X EOL chip versions."If the older version does not work, I may suggest installing the Windows Vista version of the driver instead of the Windows 11 version.I do not have a Windows machine at hand to verify the procedure, but it should be something like this:It is advisable to empty the temp before launching the installer, so you can locate the relevant directories easily.Temp directory %TEMP% eg. C:\Users\Your Name\TempDownload the installer from the profilic website, run the installer, to the end,but do not click "Finish", at the InstallSheild Wizard Complete window.In the temp directory, there should be two directories with UUID namesIn one of them, there is another UUID directory, inside there, there should beDirectories "Vista", "Win11", and "XP". Copy those directories out, there your drivers are.Then when you have extracted the driver, go to device manager, choose to change the driver, provide your own location, select the vista directory,