RX/TX Problems

Thread Starter

Paradoxz

Joined Aug 2, 2011
8
Hello again everyone! Today I am trying to get my Arduino to talk to my PIC16F690 Micro-controller. I can get them to talk, just not the same language (metaphor). Any ideas?


Parts List:
WRL-10535 Transmitter http://www.sparkfun.com/products/10535
WRL-10533 Receiver http://www.sparkfun.com/products/10533
PIC16F690 Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/41262c.pdf
Arduino Uno

Rich (BB code):
///////// CCS C Code on 16F690 (Transmitter)

#include <16F690.H>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=4000000)
#use rs232(baud=4800, xmit=PIN_A0, rcv=PIN_C3)

main() {


    while(1) {

    putc(2);

    }        

}
And for the Arduino:

Rich (BB code):
/////// Arduino Uno Code (Receiver)

int incomingByte = 0;

void setup(){

  Serial.begin(4800);

}

void loop(){

    incomingByte = Serial.read();
    Serial.println(incomingByte, DEC);


}
What it is showing:

///// putc(1); arduino serial monitor shows 64
///// putc(2); arduino serial monitor shows 2 pickit UART shows ˥
///// putc(3); arduino serial monitor shows 160 pickit UART shows ?

///// printf has so far been useless (generally correct on UART, incorrect on Arduino) I have tried millions of combinations, including:

int value = 2;
printf("%d", value);

and other correct printf formats. I have tried to configure it into a long as well since int in arduino is a long in ccsc. I have also used a byte for the receiver which is int in ccsc. They just aren't speaking the same language.



The code I am trying to adapt for the transmitter on the PIC (16F690) works with the arduino, and is as simple as



Rich (BB code):
byte this;

void setup() {

this = 2;

}

void loop() {

Serial.print(this);

}
I really hope someone knows why Serial.print on the arduino works for the transmitter but putc and printf don't work the same in CCsC


Thanks in advance.
 

Thread Starter

Paradoxz

Joined Aug 2, 2011
8
For some reason I can not locate the button to 'edit' this post. The good news, I have solved the PIC to Arduino problem, below is the code that works. Bad news, I cant seem to communicate PIC to PIC. Please see the code I am trying below and offer input.

Working:

Rich (BB code):
// The 16F690 in CCSC as Transmitter (Working)

#include <16F690.H>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=4000000)
#use rs232(baud=4800, xmit=PIN_C2, rcv=PIN_A0)

int value;
int count;

main() {

output_high(PIN_A2);


value = "0";

    while(1) {

    count = 0;

        while(count < 20) {

            if(value > 20) {

            value = 0;

            }

    
        printf("%c", value);
        count++;


    }    

value++;    

    }


}



// Arduino Uno as Receiver (Working)

int incomingByte = 0;

void setup(){

  Serial.begin(4800);

}

void loop(){

    incomingByte = Serial.read();
    Serial.println(incomingByte, DEC);


}
Not Working (Please Help):

Rich (BB code):
// Trying to use CCSC W/ 16F690 as Receiver (Not Working)

#include <16F690.H>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=4000000)
#use rs232(baud=4800, xmit=PIN_A0, rcv=PIN_B5)

int value;

main() {



    while(1) {

        value = getc();
        printf("%d", value);
        printf("\n");

    }

}

So, I can use the PIC as a transmitter, I can use the Arduino as a receiver. Can anyone help me use the PIC as the receiver? I am not sure why the code isn't working (getc())
 

hgmjr

Joined Jan 28, 2005
9,027
You may need to check to see what variable type ris eturned by the function getc(); It is most likely returning type char.

Try declaring value as type char.

hgmjr
 
Top