Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

CTS & RTS serial question RPI2

Mon Jun 01, 2015 10:29 am

Hi all!

I need to enable CTS0 and RTS0 on RPI2 for to use with a complete serial protocol like RS232.
I know that they are on pin 36 and pin 11:
http://pi.gadgetoid.com/pinout/pin36_gpio16
http://pi.gadgetoid.com/pinout/pin11_gpio17

How can I activate alt3 on C code?

Regards.

User avatar
joan
Posts: 13916
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: CTS & RTS serial question RPI2

Mon Jun 01, 2015 11:03 am

Either use a library of if you prefer not then use code like Minimal gpio access.

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Mon Jun 01, 2015 11:58 am

I am using Wiring Pi library, but I dont see where can I to active CTS0 RTS0 on pins 36 and 11. Do you know how can I active this fuctions on wiring pi?.

Regards.

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Mon Jun 01, 2015 12:09 pm

Gordon said me first to do this:

Code: Select all

 gpio -g mode 11 alt3
 gpio -g mode 36 alt3
And then re-write the Linux driver to understand the signals.
But I don't know what he refer "re-write the Linux driver".

Regards

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Mon Jun 01, 2015 2:21 pm

oh.
I did it and now rpi2 doesn't run:
EXT4-fs (mmcblk0p6): INFO: recovery required on readonly filesystem
??????????????????????'

Regards.

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Mon Jun 01, 2015 2:36 pm

If I run rpi2 without hdmi:
End kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,6)
EXT4-fs error (device mmcblk0p6) in ext4 _reserve_inode_write:4758:Journal has aborted
EXT4-fs error (device mmcblk0p6): mpage_map_and_submit_extent:2127: comm kworker/u8:1: Failed to mark inode 156343 dirty


Regards.

User avatar
joan
Posts: 13916
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: CTS & RTS serial question RPI2

Mon Jun 01, 2015 4:37 pm

If you are not using a compute module you should not be writing to gpio 36. That may be used by the SD card subsystem (which would explain why your SD card seems to have corrupted).

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 9:08 am

@joan, what can I do to use CTS and RTS on GPIO??

Regards.

User avatar
rpdom
Posts: 14085
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 10:35 am

Vaquerizo wrote:@joan, what can I do to use CTS and RTS on GPIO??
You are on the right track, just getting muddled up between physical pin numbers and GPIO numbers.

Use Pin 11 for RTS. That pin is connected to GPIO 17. So to set it you use

Code: Select all

gpio -g mode 17 alt3
Use Pin 36 for CTS. That pin is connected to GPIO 16. So to set that one you use

Code: Select all

gpio -g mode 16 alt3

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 10:38 am

???? it's a Raspberry Pi 2. Not RPI1.

User avatar
rpdom
Posts: 14085
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 10:40 am

Vaquerizo wrote:???? it's a Raspberry Pi 2. Not RPI1.
Yes. What is the problem?

The commands I gave are for Pi2 or Pi B+.

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 10:44 am

;)
Last edited by Vaquerizo on Tue Jun 02, 2015 10:50 am, edited 1 time in total.

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 10:49 am

AAAAh I understand you.
Ok Ok. Thanks so much!
And.. other question: where can I see the physical pin numbers and - GPIO numbers information?

Regards and thanks!!

User avatar
rpdom
Posts: 14085
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 10:52 am

Vaquerizo wrote:AAAAh I understand you.
Ok Ok. Thanks so much!
And.. other question: where can I see the physical pin numbers and - GPIO numbers information?
You seem to have found a very good link to a pin number reference anyway http://pi.gadgetoid.com/pinout :)

Thank you, I'll remember to bookmark that link this time :)

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 11:03 am

Aahaha I understand now.

Thanks!

Vaquerizo
Posts: 29
Joined: Tue Jan 21, 2014 4:43 pm

Re: CTS & RTS serial question RPI2

Tue Jun 02, 2015 12:02 pm

I tested and run!!! :)

fort
Posts: 1
Joined: Thu Apr 28, 2016 10:33 am

Re: CTS & RTS serial question RPI2

Thu Apr 28, 2016 11:04 am

hi
a have module UART-RS485 (ttyAMA0) connected to Raspberry Pi 2 (with raspbian).
I have also USB-RS485 (ttyUSB0) also connected. I connect them using A-B Line. Then i try transmit data between them.
my cmdline.txt:

Code: Select all

[email protected]:~/rpirtscts $ cat /proc/cmdline
dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2709.boardrev=0xa01041 bcm2709.serial=0x857e7dae smsc95xx.macaddr=B8:27:EB:7E:7D:AE bcm2708_fb.fbswap=1 bcm2709.uart_clock=3000000 bcm2709.disk_led_gpio=47 bcm2709.disk_led_active_low=0 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000  dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
To enable CTS/RTS i did this:

Code: Select all

gpio -g mode 16 alt3
gpio -g mode 17 alt3
[email protected]:~/rpirtscts $ gpio readall
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 | ALT3 | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 1 | ALT3 | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
The connect UART-RS485 module: DI to TX (pin 8), RO to RX (pin 10), DE to CTS (pin 36), RE to RTS (pin 11)/
Then i strart in window 1:

Code: Select all

screen /dev/ttyUSB0
and in second window

Code: Select all

screen /dev/ttyAMA0
Now, when send data from ttyUSB0 to ttyAMA0 it's ok: i typing data in window 1 and see it in window 2. In window 1 thus i don't see what i type.
When i typing in window 2 (send data from ttyAMA0 to ttyUSB0), i see that i type in both windows. I suppose i recieve echo. It is not right. I do not want recieve this. I need that in that it work like in first case.
Can fix this?
May be i connect UART-USB to GPIO wrong?
Do i need clearly point (and how) use RTS/CTS with ttyAMA0 when open them?

Return to “General discussion”