Skip to content

ajaygunalan/rpi3_loopback_serial

Repository files navigation

Compilation

gcc -o uart_rpi3_loopback uart_rpi3_loopback.c -lwiringPi

GitHub Repo for Reference

  1. yamaguchi-am
  2. amuthelet
  3. spiralray
  4. YuuichiAkagaw
  5. libkondo
  6. Kondo_with_ros_comples
  7. Kondo_with_ros_simple

With Pi:

Tx Pin:

oscilloscope = 800 microseconds for 115200 BaudPerSec and delay = 3.2 milliseconds

With Arduino:

Tx Pin:

oscilloscope = 80 microseconds for 115200 BaudPerSec and delay = 0.304 milliseconds

oscilloscope = 20.00 microseconds for 625000 BaudPerSec and delay = 0.064 milliseconds

oscilloscope = 8.00 microseconds for 1250000 BaudPerSec and delay = 0.049 milliseconds

Rx Pin:

Blocking

  1. stack
  2. blog
  3. a

Question?

  1. Why the fuck its not working with two while loop
  2. How to get rid of garbage value?

Make sure UART is configured in RPI3, use this as reference.

Reference

Packages to be installed:

  1. Use minicom to test if Tx --> Rx communication is established or not.

Install minicom: sudo apt-get install minicom

If java packages are missing when installing minicom, install them using the following commands:


sudo apt-get purge openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre

Test if a communication line is working by using:

sudo minicom -D /dev/ttySo

ls -l /dev | grep

Compiling and running

Compile: gcc -o test test.c -lwiringPi Run: ./test

8/02/2019 Progress

On running ics.c, the enable pin is high briefly but turns low immediately, not waiting for the data transmission to complete. Need to clear the non blocking io flag.

Created two new files ics_new.c and stoch_kondo.c. stoch_kondo.c is the final library that aims to replace wiringPi completely. I am replacing all the functions in ics_new.c for the ease of testing. Once verified to work properly, the functions are placed in stoch_kondo.c

Tried replacing the wiringPi library in the ics.c with all posix commands. Too many errors to handle when using this approach. In the end only the open and write functions were incorporated in ics.c

Increasing the delay in the code to match enable signal with tx line worked. However, it is not dynamic to adapt to transfer any number of bits Since the number of bits transmitted in all commands (setPos,getPos,set Curlim etc.), this approach is assumed to work for our purpose The delay time to be used in the code is measured by plotting the channels from an Arduino whose code is perfect and has no errors.

10/02/2019 Noon:

IMPORTANT: Added tcdrain(fd) and tcflush(fd) to ics.c and each time the tx pin is high, enable pin goes high. However, enable pin becomes low even during data transmission (i.e, when 0 is transmitted).

Documentation on tcdrain() and tcflush():

Forum on flushing unused data

  1. The use of POSIX function tcflush() is to flush all data there in the object referred by fd, but not transmitted. Usage: int tcflush(int fildes, int queue_selector);

  2. Types of queue_selectors are as follows:

    a) TCIFLUSH, it shall flush data received but not read. b) TCOFLUSH, it shall flush data written but not transmitted c) TCIOFLUSH, it shall flush both data received but not read and data written but not transmitted.

IBM support page on waiting until o/p is transmitted

Summary:

tcdrain() waits till all output sent to fd is actually sent to through the port mentioned by fd If successful, tcdrain() will return 0. Else, it returns -1. There is an example for usage availble.

QNX documentation on tcdrain x Similar to previous link. Smaller example code for the usage.

11/02/2019:

Clean up of code is complete and the expected results on oscilloscope is obtained. Refer top of this document for oscilloscope settings.

13th Feb, 2019

calculate the time taken for sending one byte in TX in UART in RPI3 and Arduino.

To do:

  1. Write a library for set functions (setPos, setCurlim, setSpd etc.)
  2. Plot the output of Rx pin using Arduino and try to replicate the same using Rpi3
  3. Figure out how to use the synchronize function in the code
  4. Mimic wave form of Rx pin obtained using Arduino using the Rpi3
  5. Complete kondo_stoch.h library by adding all the get functions (getPos, getSpd etc.)
  6. Make a similar alias using Python and test
  7. Optimisation and threading

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published