UART ft232r FTDI to PIC 16f1829 question

Thread Starter

russpatterson

Joined Feb 1, 2010
353
Hello,

I'm able to connect my Mac to serial devices (e.g. blemate2) using the ft232r, however I'm having issues getting my PIC 16f1829 to connect to the Mac via the ft232r. When I send a byte from either end, I see a response on the other end but it's the wrong data, (When I send an 'A' from the terminal program on the Mac I get 0x78 in RCREG). I thought it was a baud rate issue but I've read everything in the data sheet and tried multiple permutations and still no luck.

Here's my hardware connection setup. My PIC is running at 5V, FT232r switch is in the VCC position (as opposed to 3.3v). I have the grounds on both connected (no VCC connection should these be connected?), and both the tx-rx's connected.

Here's my code:



Code:
 #define _XTAL_FREQ 8000000

void UART_setup()
{
 // select TX and RX pins
 TRISB7 = 0; // TX Pin set as output
 TRISB5 = 1; // RX Pin set at input
 TXCKSEL = 0; // TX on RB7
 RXDTSEL = 0; // RX on RB5
 ANSB5 = 0; // clear analog 
 // set baud rate
 //SPBRG = ((_XTAL_FREQ/16)/9600) - 1;

 SPBRG = 25;
 BRGH = 0;
 BRG16 = 1; 

 // enable Asynchonous serial port
 SYNC = 0; // Asynchronous
 SPEN = 1; // Enable serial port pins

 // prepare for transmission and reception
 TXEN = 1; // enable transmission
 CREN = 1; // enable reception

 // select 8bit mode
 TX9 = 0;
 RX9 = 0;
}

char UART_get_char()
{
 if(OERR) // check for Error
 {
  CREN = 0;
  CREN = 1;
 }

 while(!RCIF); // hold the program till RX buffer is free

 return RCREG;
} 

void UART_send_char(char bt)
{
 while(!TXIF); // hold the program till TX buffer is free
 TXREG = bt; // load the transmitter with the value
} 

void UART_send_string(char* st_pt)
{
 while(*st_pt) // if there is a char
 {
  UART_send_char(*st_pt++);
 }
} 


void do_BLE_frame()
{
 //UART_send_char('A');
 //UART_send_char('B');

 char get_value = UART_get_char();
 if(get_value == '1')
 {
  blinkRate = 115;
 } 
 else if(get_value == '0')
 {
  blinkRate = 115/2;
 } 
}


I can connect the tx and rx from the PIC and send and receive the correct data. Just no luck sending to the FTDI chip or or the BLE radio.



Any help is appreciated!

Thanks!

-Russ
 

Ian Rogers

Joined Dec 12, 2012
1,136
If you are using the internal HF / MF oscillator it's not really accurate enough for USART...

I'm trying to find some resemblance between set character 'A' (0x41) and your received character (0x78) 'x'.. not shifted or inverted... Even if the clock is out,

01000001 vs 01111000..

Doesn't make sense..
 
Top