RX/TX Problems

Discussion in 'General Electronics Chat' started by Paradoxz, Sep 8, 2011.

  1. Paradoxz

    Thread Starter New Member

    Aug 2, 2011
    8
    0
    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

    Code ( (Unknown Language)):
    1.  
    2.  
    3. ///////// CCS C Code on 16F690 (Transmitter)
    4.  
    5. #include <16F690.H>
    6. #include <stdlib.h>
    7. #include <math.h>
    8. #include <stdio.h>
    9. #include <stdlib.h>
    10. #include <ctype.h>
    11.  
    12.  
    13. #fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
    14. #use delay(clock=4000000)
    15. #use rs232(baud=4800, xmit=PIN_A0, rcv=PIN_C3)
    16.  
    17. main() {
    18.  
    19.  
    20.     while(1) {
    21.  
    22.     putc(2);
    23.  
    24.     }        
    25.  
    26. }
    27.  
    28.  
    And for the Arduino:

    Code ( (Unknown Language)):
    1. /////// Arduino Uno Code (Receiver)
    2.  
    3. int incomingByte = 0;
    4.  
    5. void setup(){
    6.  
    7.   Serial.begin(4800);
    8.  
    9. }
    10.  
    11. void loop(){
    12.  
    13.     incomingByte = Serial.read();
    14.     Serial.println(incomingByte, DEC);
    15.  
    16.  
    17. }
    18.  
    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



    Code ( (Unknown Language)):
    1.  
    2.  
    3. byte this;
    4.  
    5. void setup() {
    6.  
    7. this = 2;
    8.  
    9. }
    10.  
    11. void loop() {
    12.  
    13. Serial.print(this);
    14.  
    15. }
    16.  
    17.  
    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.
     
  2. Paradoxz

    Thread Starter New Member

    Aug 2, 2011
    8
    0
    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:

    Code ( (Unknown Language)):
    1. // The 16F690 in CCSC as Transmitter (Working)
    2.  
    3. #include <16F690.H>
    4. #include <stdlib.h>
    5. #include <math.h>
    6. #include <stdio.h>
    7. #include <stdlib.h>
    8. #include <ctype.h>
    9.  
    10.  
    11. #fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
    12. #use delay(clock=4000000)
    13. #use rs232(baud=4800, xmit=PIN_C2, rcv=PIN_A0)
    14.  
    15. int value;
    16. int count;
    17.  
    18. main() {
    19.  
    20. output_high(PIN_A2);
    21.  
    22.  
    23. value = "0";
    24.  
    25.     while(1) {
    26.  
    27.     count = 0;
    28.  
    29.         while(count < 20) {
    30.  
    31.             if(value > 20) {
    32.  
    33.             value = 0;
    34.  
    35.             }
    36.  
    37.    
    38.         printf("%c", value);
    39.         count++;
    40.  
    41.  
    42.     }    
    43.  
    44. value++;    
    45.  
    46.     }
    47.  
    48.  
    49. }
    50.  
    51.  
    52.  
    53. // Arduino Uno as Receiver (Working)
    54.  
    55. int incomingByte = 0;
    56.  
    57. void setup(){
    58.  
    59.   Serial.begin(4800);
    60.  
    61. }
    62.  
    63. void loop(){
    64.  
    65.     incomingByte = Serial.read();
    66.     Serial.println(incomingByte, DEC);
    67.  
    68.  
    69. }
    70.  
    Not Working (Please Help):

    Code ( (Unknown Language)):
    1.  
    2. // Trying to use CCSC W/ 16F690 as Receiver (Not Working)
    3.  
    4. #include <16F690.H>
    5. #include <stdlib.h>
    6. #include <math.h>
    7. #include <stdio.h>
    8. #include <stdlib.h>
    9. #include <ctype.h>
    10.  
    11.  
    12. #fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
    13. #use delay(clock=4000000)
    14. #use rs232(baud=4800, xmit=PIN_A0, rcv=PIN_B5)
    15.  
    16. int value;
    17.  
    18. main() {
    19.  
    20.  
    21.  
    22.     while(1) {
    23.  
    24.         value = getc();
    25.         printf("%d", value);
    26.         printf("\n");
    27.  
    28.     }
    29.  
    30. }

    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())
     
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
Loading...