Serial Communication between Espruino - PIC16F628A

Posted on
Page
of 2
/ 2
Next
  • Hello,

    I'm trying to communicate with PIC16F628A on serial. I have a STM32F4 Discovery Board intalled Espruino.

    I have coded 16F628A with PicC. I can simulate the hex file in ISIS Proteus. It works perfect on ISIS Proteus. PIC's job is easy, reat the TX and write it to RX. So, work is a simple ECHO

    Simulation works good, but problem occurs in real world. I'm writing the hex file to PIC and wiring it with Espruino board.

    From Espruino I'm sending some chars over TX to the PIC but getting back random values on RX. You can find attached images how do I wire it.

    I think this problem is not about Espruino, because when I plug boards TX and RX pins together Espruino can write and read wery well.

    But I'm wondering about wiring or you may give me an idea.

    Here is my Espruino code :

    Serial1.setup(9600,{rx:B7,tx:B6});
    Serial1.on('data', function (data) { console.log(data); });
    
    setInterval(function(){
    	Serial1.print("Hello World");
    },500);
    

    1 Attachment

    • IMG-20150531-WA0013.jpg
  • Looks like you only have two wires? You'd need to connect RX, TX and GND - it's the same for most busses (Serial, SPI, I2C, OneWire, etc)...

    Thanks for attaching the picture though - it makes finding problems a lot easier :)

  • Thanks for attaching the picture though - it makes finding problems a
    lot easier :)

    Is this real? or are you kidding ? :)

    Yes, I have only two wires RX and TX. But there is a red-small jumber on the PIC's board. This is VDD of PIC. I think you don't mean this, you mean a GND for Serial communication.

  • or are you kidding ?

    No - some people just post up and say "it's not working!", and it makes a lot more difficult :)

    Yes, I mean ground for serial communications... I don't know where the orange and green wires go, but presumably it's to a bench supply that doesn't share the same GND as the computer's USB?

  • Orange and gren comes direct from 5V adapter. And STM32F4 Board gets the power from USB. You are right they don't share the same GND. So, Board and PIC uses different power sources.

  • Ok, so all you need to do is connect the two GNDs (STM32F4 GND and PIC GND) together and it should work...

  • Yeah, that'll do it. You always need a common ground.

  • I think I'm still doing some thing wrong. Now I'm using a 5V source for both STM32F4 and PIC, but still getting random characters. I'm going to try a debugger to see what's happening inside of the pic and write the results here.

    Thanks for your helps.

  • Do they each have the same baud rate set?

    Ok, the other thing you could do is to use a USB-TTL converter to connect straight to the PIC, to check that is doing what you want.

  • Yes, all baut rates are 9600. OK, I'm going to try a USB-TTL converter.

    Thank you for your helps

  • I notice the pic doesn't have a crystal. I don't know if PIC has this problem, but AVR chips running off internal clock sometimes fail at UART communication because the internal oscillator is so far off that the timing is wrong.

  • @DrAzzy @Gordon
    Today, It started working mysteriously. I'm sending 65 ("A") and PIC adds +1 and writes back 66 ("B"), so expected result is printing "B" every second.

    I think it was not working because of some noise.

    You can see this video to understand why I am suspecting about noise :

    Attention : This video includes brain damaging English .
    https://www.youtube.com/watch?v=W4GECIrV­Kgg

    As you can see this noise occurs at the half of the cable when I get closer my finger. I can touch the other half of cable.

    Isn't this interesting.

  • Do you have a decoupling cap on the PIC? This may well not be the problem either, but I've seen chips w/out decoupling cap do all kinds of crazy things.

  • Do you have some wireless router, cordless phone, or other crazy RF thing goin on? A a CFL lamp that is not properly grounded, or dimmable,... It looks like your body is a transmitting antenna. Latter leads me to the questions: is there a radio station close by? Or heavy powerlines passing by?

    May you have to move into a Faraday cache or make your room one... ;-)

    This are all just wild guesses, but the behavior you experience is very interesting...

  • Could it be as simple as dodgy breadboard connections?

  • @DrAzzy I don't use decoupling cap in this circuit. I'm going to try it.

    @allObjects, I could understand if my body is transmiting noise on circuit. But I can touch left side of the Cable. If my body transmiting noise, why it doesn't transmit to the left side of cable? Why it tranmits to only right side?

  • This occurs only when I test it with my notebook. Works great on my friends notebook.
    @DrAzzy Shuld I use decoupler between VCC -> GND?

  • That's very strange... (the bit about it working with one computer, but not the other).

    Decoupling/bypassing: Any and every integrated circuit should have a 0.1uf ceramic capacitor between it's Vcc and Gnd pins, as close to the pin as possible, unless otherwise stated in the datasheet, otherwise they can do all sorts of crazy stuff.

  • Any and every integrated circuit should have a 0.1uf ceramic capacitor between it's Vcc and Gnd pins, as close to the pin as possible

    Espruino has some capacitors built in, but if you haven't put anything on the PIC, that could do it.

  • Now, We could understand why this problem occurs.

    This is the exact reason;
    This problem occurs If PIC is located less than 30 CM to a charging notebook. If notebook is not charging this problem doesn't occurs. If pic located more than 30CM this problem doesn't occur.

    In my last post, I have told that this problem doesn't occurs on my friends notebook; Yes it didn't occur because we carried the curcuit near to his notebook and his notebook was working on battery.

    We have placed 1,2,3,4 and more decoupler on circuit. But it doesn't effect on this problem.

  • Hello,

    I'm sorry to activate this thread again.

    After my last post, suddenly it worked with a 0.1uf ceramic capacitor. Then I had a break on this project for 2-3 monts.

    Now, I have created an other circuit as the same of last working one. But getting the same error. Now in my test results pic allways flooding CL-LF (Char 10 and Char 13).

    But when I put the circut 30 cm away from my notebook, it doesn't flood 10 and 13 char.

    Espruino board and pic connected to the same power source with the same ground. I have tried more than 10 capacitors, but result is the same. I can only guess that all my capacitors are broken. Tomorrow I'm going to buy new capacitors.

    Capacitors code is "104" I think I'm using the right one.

    Do you have any other idea?

  • Something in your circuit works as a Wifi or other RF antenna... (assuming you use Wifi. It could alos be that your CPU clock is 'heard' quite 'loudly'...

    Open - or not strong enough pulled-up or pulled-down inputs, lousy connections, and lousy ground/GND connections can cause this issue...

  • I think the pic is reacting to noise, and sending CRLF sequences in response to said noise. Examine the code on the pic to see if there's any way that high impedance pins (inputs) transitioning randomly due to noise could make it do that.

  • Could it be that the PIC's RX pin isn't connected to Espruino's TX pin? Or that Espruino's TX pin isn't configured as an output (Serial wasn't set up?).

    Sometimes people add a pull-up resistor to the serial lines to ensure that they stay in the high state before the Microcontroller boots up and sets the pin state correctly.

  • I want to shoot my self, it was only about the LVP Fuse on pic. I have disabled the LVP Fuse and now it works great with only a 0.1uf ceramic capacitor.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Serial Communication between Espruino - PIC16F628A

Posted by Avatar for fobus @fobus

Actions