-1

I am currently working on transmitting from a PIC18F4620, through a FT232, to CoolTerm. I am currently only receiving FF and FE from the PIC though. I was wondering why this may be the case. The Rx - TX are correctly switched, the cable connecting them appears to be secure. The only issue I can think of is the baud rate would be incorrect, But looking at the datasheet I don't believe it is. any insight would be greatly appreciated. (I arbitrarily chose 51 as my test number. any number or letter would work).

Circuit



const unsigned char MSG0[] = "Transmitting... ";
const unsigned char MSG1[] = "Sent:";
const unsigned char MSG2[] = "TEST:";

// Subroutine Declarationsb
#include <pic18.h>

// Subroutines
#include        "lcd_portd.c"

#include <delays.h>
#include <plib.h>
#include <stdint.h>

void UART_TX_Init(void)
{
    BRG16 = 0;
    BRGH = 1; // Set For High-Speed Baud Rate
    SPBRG = 64; // Set The Baud Rate To Be 9600 bps
  //--[ Enable The Ascynchronous Serial Port ]--
    SYNC = 0;
    SPEN = 1;
  //--[ Set The RX-TX Pins to be in UART mode (not io) ]--
    TRISC6 = 1;  // As stated in the datasheet
    TRISC7 = 1;  // As stated in the datasheet
    TXEN = 1; // Enable UART Transmission
}

void UART_Writes(uint8_t data)
{
    while(!TRMT);
    TXREG = data;
}

// Main Routine
void main(void)
{
    UART_TX_Init();
    unsigned int result = 0;
    unsigned int i;
    uint8_t      data = 51;
    TRISA = 0;
    TRISC = 0;
    TRISB = 0;
    TRISD = 0;
    TRISE = 0;
    TRISA = 0;
    TRISB = 0x00;
    PORTC = 0;
    PORTD = 0;
    PORTE = 0;
    ADCON1 = 0x0F;

    LCD_Init();                  // initialize the LCD
    LCD_Move(0,0);  for (i=0; i<20; i++) LCD_Write(MSG0[i]); 
    Wait_ms(100); 
    LCD_Move(1,0);  for (i=0; i<5; i++) LCD_Write(MSG1[i]); 
    while(1) {
        Wait_ms(1000);
        UART_Writes(data);
        LCD_Move(1,5); LCD_Out(data,3,0);
    }
}


CoolTerm

Mike
  • 4,041
  • 6
  • 20
  • 37
Petertk
  • 1
  • 1
  • 1
    Unrelated to your problem, but please try to reformat the code to make the indentation consistent. Inconsistent indentation makes the code harder to read and follow. Case in point: The `UART_Writes` function, where at a quick glance it looks like `TXREG = data;` is inside the loop. – Some programmer dude Apr 28 '21 at 03:56
  • 1
    More related to your problem, are start-bits, stop-bits, parity, baud-rate etc. exactly the same on both sides? – Some programmer dude Apr 28 '21 at 03:57
  • 2
    Do you have a scope trace to confirm if the waveform on the wire is as expected? – nanofarad Apr 28 '21 at 03:58
  • 3
    "receiving FF and FE" indicates the receiving side is using incorrect baud or some such incorrect setup. – chux - Reinstate Monica Apr 28 '21 at 05:46

1 Answers1

-1

What is your clock frequency and how did you configured your crystal oscillator setup ? please share your clock setting and configuration.

If clock setting is fine then calculate the correct baud-rate and try.

void UART_Writes(uint8_t data)
{

while(!TRMT)
{
  //put Nop() and try
}
    TXREG = data;
}
  • 1
    Actually this does not answer the question. Did you mean to post a comment? – the busybee Apr 28 '21 at 06:00
  • I have posted the circuit in the post above. – Petertk Apr 29 '21 at 01:39
  • @thebusybee , The reason behind junk is most probably is unstable crystal setup or baud-rate rather then physical wire connection issue, or it may be wrong configuration of the UART. – Ketan Vadodariya Apr 29 '21 at 04:47
  • 1
    Sure, but you did not post an answer saying that this is the case here. You're asking the OP, which belongs in a comment below the question, so that the OP can react and extend the question. -- And the source you show is the equivalent to the OP's, except you replaced the semicolon by curly braces. This is also not an answer to the question, because it changes nothing. – the busybee Apr 29 '21 at 07:52