Hi every body! I'm doing a project with PSoC 1 CY8C24123A. Hardware: -My software on PC - COM cable - RS485 to COM circuit (have MAXIM232 (1 device)- MAXIM485(1 device)) - CY8C24123A board (have a SN75176B...). A,B signal of SN75176B conect to A,B signal MAXIM485. (I'm using RS485 standard, baudrate is 19200). -Communication between PC and CY8C24123A via UART user module, but TX and RX connect to same pin. -Pin P0.4 is TX and RX. I have to configure pin 0.4. -P0.2 control SN75176B to transmit or receive data. P0.2 = 1 transmit; P0.2 = 0 receive. Contents: - PC will send data to PSoC, after that PSoC send data to PC. -If PSoC received 3 bytes 0xAA from PC. After that PSoC send 0xAA ,0x31, 0x00 to PC. -If PSoC received 3 bytes 0xBB from PC. After that PSoC send 0xBB ,0x33, 0x00 to PC. But communication is not good. Some times, PC received data fail or receive data not truely. I think when I switch between TX and RX at the same pin not well! Can you tell me solutions to solve that problem? Many thanks. Below is my project!
You have to consider that a byte to send will first be removed from the FIFO-buffer (which is empty then) and put into the TX-register which is not empty now. You have to wait until the transmission is done before switching to receive mode.
There is no delay needed after switching the pin modes, you only have to be sure that there is actually no transmission running that you will abort by reprogramming the IO-pin.
What I am dubuous about is the fact, that you wait for 3 similar characters so that you are not able to tell when you missed one char whether you expect now the second to the third (or the first). When you have influence on the protocol I would suggest to send a lead-in character (SOT is a good candidate) to get the begin of a message.