CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Can't send data to PC from PIC using USB-TTL

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zugzwang



Joined: 02 Aug 2018
Posts: 2

View user's profile Send private message

Can't send data to PC from PIC using USB-TTL
PostPosted: Thu Aug 02, 2018 8:59 am     Reply with quote

I'm using a USB-TTL FT232RL http://buyhere22.com/components/usb-ttl-ft232rl-pinout.png connected to a PIC16F877A. I'm only using the TX & RX ports of the USB-TTL connected to the RX & TX of the uC respectively. The USB-TTL powers up when connected to the PC.

I want to see the data of the MPU6050 GY-521 on my PC, however, I can visualize it on the LCD screen without any problems.
By the way, I'm using HTerm to receive the data coming from the USB-TTL, so it seems, IMO, that the uC is not sending any instructions to the USB-TTL to be ready to send data.
Pls help Sad Question

i2cmain.h:

Code:
#include <16F877A.h>
#device ADC=10
 
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES HS
 
#use delay(crystal=20000000)


Main:

Code:
#include <i2cmain.h>
#use standard_io(C)
#use standard_io(D)
#use standard_io(B)
#define Master_to_slave 0xD0 //!Para escribir datos al slave //! Con AD0 = 0;
#define Slave_to_master 0xD1 //!Para leer datos del slave //! Con AD0 = 0;
#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7, errors, stream=RS232)
#use i2C(master, scl=PIN_C3, sda=PIN_C4, fast, force_hw)

#define LCD_ENABLE_PIN  PIN_D0                                   
#define LCD_RS_PIN      PIN_D1                                   
#define LCD_RW_PIN      PIN_D2                                   
#define LCD_DATA4       PIN_D4                                   
#define LCD_DATA5       PIN_D5                                   
#define LCD_DATA6       PIN_D6                                   
#define LCD_DATA7       PIN_D7 
#include <lcd.c>

#define MPU6050_PWR_MGMT_1 0x6B

signed int16 accel_xout;
signed int16 accel_yout;
signed int16 accel_zout;

#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40

int16 MPU6050_Leer_Registro(int8 registro){
int8 msb, lsb;
int16 valor;

i2c_start();
i2c_write(Master_to_slave);
i2c_write(registro);
i2c_start();
i2c_write(Slave_to_master);
msb = i2c_read(0);
i2c_stop();

i2c_start();     
i2c_write(Master_to_slave);
i2c_write(registro + 0x01);
i2c_start();
i2c_write(Slave_to_master);
lsb = i2c_read(0);
i2c_stop();
     
valor = make16(msb,lsb);

return (valor);
}

void Get_Accel_Values(void){

accel_xout = MPU6050_Leer_Registro(ACCEL_XOUT_H);
//!accel_yout = MPU6050_Leer_Registro(ACCEL_YOUT_H);
//!accel_zout = MPU6050_Leer_Registro(ACCEL_ZOUT_H);
output_low(Pin_B7);
delay_ms(150);
}

void MPU6050_Setup(){

delay_ms(100);

i2c_start();
i2c_write(Master_to_slave);
i2c_write(MPU6050_PWR_MGMT_1);
i2c_write(0x00);
i2c_stop();

delay_ms(100);
}


void main()
{
   lcd_init();
   lcd_gotoxy(1,1);
   MPU6050_Setup();
//!   char string[30];
   

   while(TRUE)
   {
      lcd_putc("\f");
      Get_Accel_Values();
      printf(lcd_putc,"%ld",accel_xout);
      fprintf(RS232,"%ld",accel_xout);
//!      sprintf(string,"%ld",accel_xout); //!ld = long signed
//!      printf("Hola Mundo!");
      output_high(Pin_B7);
      delay_ms(150);
     
     
   }

}


Last edited by Zugzwang on Thu Aug 02, 2018 9:19 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Aug 02, 2018 9:06 am     Reply with quote

One thing leaps out.
Jumper for 5v/3.3v.
First thing have you got this set to 5v (needed).
Second is what chip is used. Read it's part number and get it's data sheet.
Check what it's output voltage actually is?.
PIC serial needs a signal that goes up to 4v. Many '3.3v' boards even if they have an option to jumper their regulator for 5v, do not give sufficient output to be seen by the PIC....
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 02, 2018 10:26 am     Reply with quote

Simple test. install a jumper from the module TX to RX pins (no PIC connections). Now, every keypress on the PC KBD should be seen on the PC monitor.
IF this works, you've confirmed PC end is OK.

Do you have PIC TX connected to module RX, PIC RX to module TX ?

Jay
Zugzwang



Joined: 02 Aug 2018
Posts: 2

View user's profile Send private message

Re: Can't send data to PC from PIC using USB-TTL
PostPosted: Thu Aug 02, 2018 12:05 pm     Reply with quote

Ok guys, I have found the solution and it's very simple. I though the only neccesary connections were the TX & RX of the USB-TTL because of previous projects I've made sending data FROM the PC to the uC without any problems.

But while reading the datasheet of this module it says I also have to connect the GND pin on my protoboard. That's all.
However I still wonder why since the power source for the USB-TTL is my PC USB Port and for my uC (which is on my protobard) is an independet 5v-DC source.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Aug 02, 2018 12:27 pm     Reply with quote

Aaargh!......

You always need a ground connection. You've just been lucky in the past that parts you have been using happen to have their grounds connected to the same place.

Your usb module is using usb power to run it. It is powered from the PC. Your PIC is running off a wall-wart I guess, which is an isolated supply.
Something like 80% of circuitry now does not use the mains ground. It floats. That includes things like laptop PC's....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group