2

I'm actually working with a PIC32MX795F512L and MPLABX V2.10 and XC32 on a little project et I need to send data (for now, just 0 or 1) via RX/TX to "something" that convert it to USB.

The problem is that i'm receiving strange things

 #define UART_BAUD_RATE 9600
 char* cmd;
 int main(void) { 
     UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY);
     UARTSetFifoMode(UART1, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
     UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
     UARTSetDataRate(UART1, GetPeripheralClock(), UART_BAUD_RATE);
     UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
     while (1)
     {
         cmd="1";
         uart_send_data((BYTE*)cmd,1);

The uart_send_data function is:

void uart_send_data(BYTE *buffer, UINT8 size)
{
    UINT8 i;
    for( i=0; i<size; i++ )
    {
        uart_put_c(*buffer);
        buffer++;
    }

    while(!UARTTransmissionHasCompleted(UART1));
}

And then uart_put_c:

void uart_put_c(char c)
{
    while(!UARTTransmitterIsReady(UART1));
    UARTSendDataByte(UART1, c);
}

So, I'm sending a 1 or a on TX1. But, when I look at what I'm receiving on my USB port (thanks to Docklight) i get in ascii: ð |ð, in hex: 0C F0 00 F0 0C ect ... So, does someone knows where my problem is coming from?

Thansk in advance.

Cheers

TripeHound
  • 2,721
  • 23
  • 37
DesireM
  • 23
  • 5
  • I don't know the hardware, but **(a)** I doubt it is, but ensure nothing else might be using the UART; **(b)** Try sending a longer string, e.g. "123ABC" to have a better chance of seeing if there's a pattern to the incorrect data; **(c)** Can you hook something more directly to the TX pin to see whether it's the UART or the USB thing that's the problem? – TripeHound Jul 08 '15 at 10:35
  • I don't have anything else in this project. I'm just trying to configure the right way my communication. I've tried to send 123ABC and I obtain "0C 70 F0 70 F0 00 0C 00 8C 00 FC" in hex. In ASCII I have pðpðp | – DesireM Jul 08 '15 at 11:35
  • I can't see any pattern between the two... if you cannot monitor the UART output more directly than through the USB "thing" then I think you need someone who knows your hardware. Sorry. – TripeHound Jul 08 '15 at 12:09
  • 1
    Have you checked that you configured the same baud rate at both ends? If you're using a TTL to USB converter, also make sure you connected TX-RX and RX-TX. – Roger Rowland Jul 08 '15 at 12:19
  • 1
    Ok guys, by looking with the oscilloscope what I'm sending I easily see the bits. I think that the problem is due to the convertisseur RS/USB. Sorry for your time, my bad. But thank you! – DesireM Jul 08 '15 at 12:32

0 Answers0