Pages: [1]   Go Down
Author Topic: quick question about serial comm. w/pic16f88  (Read 1215 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First of all, I'm new to this and not sure if I'm posting in the correct area of the forums.  I'm trying to get my arduino mega to talk to a pic16f88 via serial.  I have a joystick input to the arduino, I've mapped it and converted it to a 0/1 serial output to a pic.  I want the pic to send a pin high when it sees a 1 following an "A" and send the pin low when it sees a 0 following an "A".  My pic doesn't respond to the serial input the way everyone has suggested my code should.  I also don't have any way to check the serial on the pic side except to watch the output on the intended pin and send serial output to the arduino.

Here's my arduino code:
Code:
int joy1vin = A1;    // analog pin used to connect joystick 1 vertical axis
 int joy1v;
 int joy1hin = A2;
 int joy1h;
 int joy1sel = A3;
 
 int joy2vin = A4;    // analog pin used to connect joystick 2 vertical axis
 int joy2v;
 int joy2hin = A5;
 int joy2h;
 int joy2sel = A6;
 
 int thr1;
 int thr2;
 int thr3;
 int thr4;
 
 int BEEP = 13;       // analog speaker connected to pin 13
 
 String serialDataOut;
 
  void setup()
{
  Serial.begin(9600);
 
  }
 
 void loop()
{
 
  //while (Serial.available() > 0)
 //{
    //char serialByte = Serial.read();
    //Serial.println(serialByte);
  //}   
 
  joy1v = analogRead(joy1vin);
  joy1v = map(joy1v, 0, 1024, 100, 999); 
   
  joy1h = analogRead(joy1hin);
  joy1h = map(joy1h, 0, 1024, 100, 999);
 
  joy2v = analogRead(joy2vin);
  joy2v = map(joy2v, 0, 1024, 100, 999);
 
  joy2h = analogRead(joy2hin);
  joy2h = map(joy2h, 0, 1024, 100, 999);
 
  if (joy1v>600)
  thr1=1;
  else thr1=0;
 
  if (joy1v<400)
  thr2=1;
  else thr2=0;
 
  if (joy1h>600)
  thr3=1;
  else thr3=0;
 
  if (joy1h<400)
  thr4=1;
  else thr4=0; 
 
  Serial.print("A");
  Serial.print(thr1, DEC);
  Serial.print("B");
  Serial.println(thr2, DEC);
  Serial.print("C");
  Serial.println(thr3, DEC);
  Serial.print("D");
  Serial.println(thr4, DEC);

And my pic code:
Code:
#CONFIG
    __CONFIG _CONFIG1, _INTRC_IO & _PWRTE_ON & _MCLR_OFF & _LVP_OFF
#ENDCONFIG

DEFINE OSC 8
OSCCON.4 = 1
OSCCON.5 = 1
OSCCON.6 = 1

ANSEL = 0
CMCON=7

INCLUDE "modedefs.bas"

'DEFINE HSER_RCSTA 90h    'set receive register to receiver enabled
'EFINE HSER_TXSTA 20h    'set transmit register to transmitter enabled
'DEFINE HSER_BAUD 9600    'set baud rate
'DEFINE HSER_CLROERR 1  'clear overflow errors

ON INTERRUPT GOTO serial

'INTCON = %1100100
'PIE1 = %00100000
'PIR1 = %00000000
'RCIF VAR PIR1.5


'motor1 = portb.0 'assign main motor 1 to pin 6
'motor2 = portb.1 'assign main motor 2 to pin 7
'thr1 = portb.3 'assign thruster motor 1 to pin 9
'thr2 = portb.4 'assign thruster motor 2 to pin 10
'thr3 var portb.6 'assign thruster motor 3 to pin 12
'thr4 var portb.7 'assign thruster motor 4 to pin 13
'tempout var porta.0 'assign temperature sensor output to pin 17
'voltout var porta.1 'assign thruster battery (not main batteries)
                     'voltage sense output to pin 18

joy1v var word
joy1h var word
joy2v var word
joy2h var word
mode  con 2

thr1vin var portb.2
thr1hin var portb.1

thr1vout var portb.6


'portb.0 = 0
'portb.1 = 0
'portb.3 = 0
'portb.4 = 0
'portb.6 = 0
'portb.7 = 0
'porta.0 = 0
'porta.1 = 0

TRISA = %11111100 'set RA 0 & 1 as outputs
TRISB = %00100100 'set RB 2 & 5 as inputs


Main:  'Loop to keep your code from running down and dripping all into your other routines
while 1
thrusters:
if (joy1v==1) then
high portb.3
Pause 250
Low portb.3
Pause 250
endif

if (joy1v==0) then 
low portb.3     
endif

if (joy1h==1) then
high portb.4
Pauseus 250
Low portb.4
Pauseus 250
endif

if (joy1h==0) then
low portb.4
endif

wend

serial:
serin thr1vin, 2, ["A"], joy1v
serout thr1vout, 2, joy1v
return

end

I've tried serin and hserin on the pic, neither seems to be doing what I think it should.  I know it's possible, but I don't know it isn't working.  Is there anything that really stands out that I might be doing wrong? 

Thanks in advance
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 643
Posts: 50443
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Here's my arduino code:
Which won't even compile.

Why not disconnect the joystick, delete all the commented out code, and just send one or two characters, until you KNOW that communication is happening?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it compiles just fine for me.  The serial monitor shows that the data is being transmitted from the arduino correctly, but I have no way of knowing if the pic is receiving. 

I've tried bypassing the joystick and just blinking an LED on the pic, but I get nothing.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 643
Posts: 50443
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it compiles just fine for me.
Not the code you posted. It is missing, at the least, a closing curly brace at the end of loop.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you can probably find the little curly bracket thingy on your keyboard... smiley-wink
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, so we're supposed to know that nothing else is missing?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing else is missing because when I copy it back and add the brace it works the way it always has.

Code:

int joy1vin = A1;    // analog pin used to connect joystick 1 vertical axis
 int joy1v;
 int joy1hin = A2;
 int joy1h;
 int joy1sel = A3;
 
 int joy2vin = A4;    // analog pin used to connect joystick 2 vertical axis
 int joy2v;
 int joy2hin = A5;
 int joy2h;
 int joy2sel = A6;
 
 int thr1;
 int thr2;
 int thr3;
 int thr4;
 
 int BEEP = 13;       // analog speaker connected to pin 13
 
 String serialDataOut;
 
  void setup()
{
  Serial.begin(9600);
 
  }
 
 void loop()
{
 
  //while (Serial.available() > 0)
 //{
    //char serialByte = Serial.read();
    //Serial.println(serialByte);
  //}   
 
  joy1v = analogRead(joy1vin);
  joy1v = map(joy1v, 0, 1024, 100, 999); 
   
  joy1h = analogRead(joy1hin);
  joy1h = map(joy1h, 0, 1024, 100, 999);
 
  joy2v = analogRead(joy2vin);
  joy2v = map(joy2v, 0, 1024, 100, 999);
 
  joy2h = analogRead(joy2hin);
  joy2h = map(joy2h, 0, 1024, 100, 999);
 
  if (joy1v>600)
  thr1=1;
  else thr1=0;
 
  if (joy1v<400)
  thr2=1;
  else thr2=0;
 
  if (joy1h>600)
  thr3=1;
  else thr3=0;
 
  if (joy1h<400)
  thr4=1;
  else thr4=0; 
 
  Serial.print("A");
  Serial.print(thr1, DEC);
  Serial.print("B");
  Serial.println(thr2, DEC);
  Serial.print("C");
  Serial.println(thr3, DEC);
  Serial.print("D");
  Serial.println(thr4, DEC);
 
}
Logged

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
just send one or two characters, until you KNOW that communication is happening
I'd go with that,
is that proton basic?
why would you need to use a pic in conjunction with atmega? one or other should be more than capable alone
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26525
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
'EFINE HSER_TXSTA 20h
You're quite sure nothing is missing?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
'EFINE HSER_TXSTA 20h
You're quite sure nothing is missing?

' is a rem or // in proton basic, but yeah he's missing the D but in this case it's ignored
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
'EFINE HSER_TXSTA 20h
You're quite sure nothing is missing?

the apostrophe (') at the beginning of that line prevents it from being compiled.  That particular define was added when I was trying to use hserin instead of serin, that line was disabled (and the "d" deleted with no consequence) when I switched.

Code:
'DEFINE HSER_TXSTA 20h
 


Quote
just send one or two characters, until you KNOW that communication is happening
I'd go with that,
is that proton basic?
why would you need to use a pic in conjunction with atmega? one or other should be more than capable alone


It's picbasic pro running on MXC studio, compiled with melabs pro.

I have already tried just sending single bits/characters, with no result.  I even tried sending simple strings to make an LED blink, nothing.  I've been struggling with this for a couple weeks and I've tried everything everyone else I've talked to has suggested (my lab TA's, my professor, previous students, EE/ECE students, you name it).  

The reason I'm using both is once I have this serial issue resolved we plan on having them communicate wirelessly (I know, I know, I can't even resolve a simple serial issue, why on earth would I still consider wireless at this point, right???.....wireless isn't my concern right now, someone else in my group is working on that).  But I'm using the pic instead of an arduino because it's a requirement to use a pic for my class project (serial isn't part of the requirement, and the programming "skills" we've learned in class for the pic have been all but worthless).  We're mechanical engineering students trying to set up a two-way remote control for a simple UAV.  The UAV flies just fine when we set it up with conventional RC equipment, now we have to set it up with the requisite hardware.

I'm using single wires for serial communication until we know that it works, then move to wireless.  
Logged

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it's been a while since i used proton basic but a few things to check are you tx & rx wires are the right way round, also serial polarity because if your using a max 232 between uC ans PC the signal will be inverted, you can set that in basic, I dont think the f88 has hardware uart so forget HSER, stick with serin serout, make sure your xtal frequency is correctly define or serial wont have a chance, for now forget arduino part of it and just get the pic to talk to pc
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it's been a while since i used proton basic but a few things to check are you tx & rx wires are the right way round, also serial polarity because if your using a max 232 between uC ans PC the signal will be inverted, you can set that in basic, I dont think the f88 has hardware uart so forget HSER, stick with serin serout, make sure your xtal frequency is correctly define or serial wont have a chance, for now forget arduino part of it and just get the pic to talk to pc

I suppose that's what I should do, but all the computers I have access to run windows 7, so getting access to hyperterminal will be an issue.....I have checked and rechecked my TX and RX wires (TX to RX, vice versa).  And no, I'm not using a max232 or anything like that. 

Thanks!
Logged

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've problems with hyperterm previously, I thought pic basic came with Term.exe? It's not imeadiatly visible so  do a search in windows for term.exe
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2928
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PuTTy works well... And it's Free...

Bob
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Pages: [1]   Go Up
Jump to: