KAmod RPI 485 CAN Hat: Difference between revisions
From Kamamilabs.com - Wiki
| Line 320: | Line 320: | ||
[[File:KAmod_RPI_485%26CAN_Hat_ster_LED.png|none|600px|thumb|center]] | [[File:KAmod_RPI_485%26CAN_Hat_ster_LED.png|none|600px|thumb|center]] | ||
</center> | </center> | ||
===== <b>Konfiguracja sygnałów SPI CE </b>===== | ===== <b>Konfiguracja sygnałów SPI CE </b>===== | ||
Revision as of 06:39, 3 June 2025

Description
KAmod RPI 485&CAN Hat - Module with two RS485 interfaces and a CAN interface for Raspberry Pi
KAmod RPI 485&CAN Hat allows you to easily expand Raspberry Pi 5 computers with two RS485 interfaces and one CAN 2.0B interface. The interfaces contain extensive protection circuits and are galvanically isolated from the control circuits, which guarantees stable operation and resistance to interference and failures. The module has been designed to be compatible with Raspberry Pi series boards not only in version 5. It is controlled via 2 SPI interfaces, available on the 40-pin RPi connector, and in many other boards, e.g. Arduino, STM32, etc.
Basic features and parameters
- 2 RS485 interfaces – controlled by SC16IS752 controller (SPI→2xUART)
- 1 CAN 2.0B interface – controlled by MCP2515 controller (SPI→CAN)
- RS485 interfaces equipped with 2 isolated ADM2483 transceivers
- CAN interface equipped with isolated TJA1052 transceiver
- RS485 and CAN interfaces galvanically separated from control circuits
- Possibility to connect 120 Ω terminating resistors to each interface line
- Maximum RS485 interest communication speed: 500 kbps
- Maximum CAN interest communication speed: 1 Mbps
- Control via two SPI interfaces operating with 3.3 V voltage
- Automatic control of RS485 transceiver transmission direction
- Power supply 5 V/0.3 A taken from the Raspberry Pi board or from an additional source
- Optional power input adapted to a voltage in the range of 8...32 V
- Stabilized power output 5 V, max 0.5 A
- Easy installation on Raspberry Pi 5, also in the version with the RPi Active Cooler radiator
- Can work with many boards from the Raspberry Pi family and others equipped with SPI interfaces operating at a voltage of 3.3 V
- Module dimensions 65x56 mm, height approx. 15 mm (and a connector under the board with a height of approx. 13 mm)
Standard Equipment
| Code | Description |
|---|---|
| KAmod RPI 485&CAN Hat |
|
| Mounting Kit |
|

Block diagram

Circuit diagram
The circuit diagram of the KAmod RPI 485&CAN Hat module can be downloaded here: KAmod RPI 485&CAN Hat diagram
RS485 Interfaces
| Interface | Element | Function |
|---|---|---|
| RS485-1 |
Connector |
Connecting a 120 Ω terminating resistor to the RS485-1 bus line, |
|
Connector |
Main RS485-1 bus connector, pin 1 – GND; pin 2 – B(-); pin 3 – A(+) | |
|
Connector |
Additional RS485-1 bus connector, pin 1 – GND; pin 2 – B(-); pin 3 – A(+) | |
|
LED |
The diode lights up to indicate data transmission/reception on the RS485-1 interface signal lines | |
| RS485-2 |
Connector |
Connecting a 120 Ω terminating resistor to the RS485-2 bus line, |
|
Connector |
Main RS485-2 bus connector, pin 1 – GND; pin 2 – B(-); pin 3 – A(+) | |
|
Connector |
Secondary RS485-2 bus connector, pin 1 – GND; pin 2 – B(-); pin 3 – A(+) | |
|
LED |
The diode lights up to indicate data transmission/reception on the RS485-2 interface signal lines |
The RS485 interfaces are controlled by ADM2483 transceivers, which also provide galvanic separation between the control signals and the RS485 bus lines.
The bus lines are marked as: A(+), B(-) and GND ground and are available on the Phoenix MC connector (R1J2, R2J2) and on goldpin pins with a standard 2.54 mm pitch (R1J3, R2J3). Their arrangement is shown in the drawing and is described on the bottom side of the module board.
The RS485 bus lines are equipped with circuits protecting against overvoltages. Putting a jumper on pins 2-3 of RxJ1 allows you to connect a 120 Ω terminating resistor between lines A and B of the interface.

CAN Interface
| Interface | Element | Function |
|---|---|---|
| CAN |
Connector |
Connecting a 120 Ω terminating resistor to the CAN bus line, |
|
Connector |
Main CAN bus connector, pin 1 – GND; pin 2 – CAN L; pin 3 – CAN H | |
|
Connector |
Additional CAN interface connector,
pin 1 – GND; pin 2 – CAN L; pin 3 – CAN H | |
|
LED |
The diode lights up to indicate data transmission/reception on the CAN interface lines |
The CAN interface is controlled by a TJA1052 transceiver, which also provides galvanic separation between control signals and the CAN bus lines.
The bus lines are marked as: CAN H, CAN L and ground GND and are available on the Phoenix MC (CJ2) type connector and on goldpins (CJ3) with a standard 2.54 mm pitch. Their layout is shown in the drawing and is described on the bottom side of the module board.
The CAN bus lines are equipped with circuits that protect against overvoltages. Putting a jumper on pins 2-3 of CJ1 allows you to connect a 120 Ω terminating resistor between the CAN H and CAN L lines.

RS485 Control
| RS485 Interfaces | |
|---|---|
| Control Signal | Function |
| MOSI1 (SPI 1) | SPI data input of SC16IS762 controller, connected to GPIO20 RPi (pin 38 of J3) |
| MISO1 (SPI 1) | SPI data output of SC16IS762 controller, connected to GPIO19 RPi (pin 35 of J3) |
| SCLK1 (SPI 1) | SPI clock input of SC16IS762 controller, connected to GPIO21 RPi (pin 40 of J3) |
| RS CE | SPI interface activation input of SC16IS762 controller |
| By default connected to GPIO07 (pin 26 of J3 connector) - Shorted jumper JP3 | |
| Optionally connected to GPIO18 (pin 12 of J3 connector) - Shorted jumper JP4 | |
| RS INT | SC16IS762 controller IRQ interrupt output connected to GPIO24 (pin 18 of J3 connector) |
All control signals are led out on connector J1 (40-pin, compatible with Raspberry Pi boards) and on pin header J2. The signal layout is shown in the figure below, additionally the signals on connector J2 are described on the bottom side of the KAmod RPI 485&CAN Hat board.
RS485 interfaces are implemented via the SC16IS762 controller, the description of this system is available in the manufacturer's documentation.

CAN Control
| CAN Interface | |
|---|---|
| Control Signal | Function |
| MOSI0 (SPI 0) | MCP2515 Controller SPI Data Input Connected to GPIO10 RPi (J3 Pin 19) |
| MISO0 (SPI 0) | MCP2515 controller SPI data output connected to RPi GPIO09 (J3 pin 21) |
| SCLK0 (SPI 0) | MCP2515 controller SPI clock input connected to RPi GPIO11 (J3 pin 23) |
| CAN CE | MCP2515 controller SPI interface enable input |
| By default connected to GPIO08 (J3 pin 24) - JP1 jumper closed | |
| Optionally connected to GPIO07 (pin 26 of J3 connector) - Shorted jumper JP2 | |
| CAN INT | MCP2515 controller IRQ interrupt output connected to GPIO25 (pin 22 of J3 connector) |
All control signals are output on connector J1 (40-pin, compatible with Raspberry Pi boards) and on pin connector J2. The signal layout is shown in the figure below, additionally the signals on connector J2 are described on the bottom side of the KAmod RPI 485&CAN Hat board.
The CAN interface is implemented via the MCP2515 controller, a description of the operation of this system is available in the manufacturer's documentation.

Power Supply
| Element | Function |
|---|---|
| Connector J1 PWR |
Optional power supply input adapted to a voltage in the range of 8...32 V. Powers the integrated switching regulator, which provides a voltage of 5 V with a capacity of up to 0.5 A, to power the components of the KAmod RPI 485&CAN Hat module. |
| Connector J2 |
Connector J2 provides 5V from the integrated regulator. It can be used as a power source for additional circuits or modules. The current consumption should not exceed 0.5A. |
| Connector J1 |
Connector J1 provides 5V from a base board, e.g. Raspberry Pi. This voltage is connected via a rectifier diode to the 5V power supply of the KAmod RPI 485&CAN Hat module, so the module is powered from the base board, but the module cannot supply power to the base board. |
| LED D12 | LED D12 lighting indicates power supply |
The KAmod RPI 485&CAN Hat module offers various power supply options:
- can be powered by 5V from a base board connected to connector J1, e.g. Raspberry Pi. No external power supply is required;
- can be powered by a voltage in the range of 8...32 V connected to connector J1 PWR. Then a stabilized voltage of 5 V is available on connector J2, but it does not power the base board connected to connector J1;
- can be powered by a stabilized voltage of 5 V connected to connector J2, but it does not power the base board connected to connector J1;
The layout of the connectors and contacts and their polarity are shown in the figure.

1 046 / 5 000
Indicator lights
| Indicator light | Function |
|---|---|
| D7 | The diode lights up to indicate data transmission/reception on the RS485-1 interface signal lines |
| D5 | The diode lights up to indicate data transmission/reception on the RS485-2 interface signal lines |
| D10 | The diode lights up to indicate data transmission/reception on the CAN interface signal lines |
| D12 | The diode lights up to indicate power supply |
The layout of the signaling lights on the KAmod RPI 485&CAN Hat board is shown in the figure.

Konfiguracja sygnałów SPI CE
| Sygnał | Funkcja | |
|---|---|---|
| CAN CE | Wejście aktywujące interfejs SPI kontrolera MCP2515 | |
| Domyślnie połączone do GPIO08 (pin 24 złącza J3) | Zwarta zwora JP1 | |
| Opcjonalnie połączone do GPIO07 (pin 26 złącza J3) | Zwarta zwora JP2 | |
| RS CE | Wejście aktywujące interfejs SPI kontrolera SC16IS762 | |
| Domyślnie połączone do GPIO07 (pin 26 złącza J3) | Zwarta zwora JP3 | |
| Opcjonalnie połączone do GPIO18 (pin 12 złącza J3) | Zwarta zwora JP4 | |
Moduł KAmod RPI 485&CAN Hat realizuje komunikację z płytką bazową np. Raspberry Pi poprzez dwa interfejsy SPI. Sygnały CE – Chip Enable, obu interfejsów mogą być połączone w dwóch konfiguracjach, w zależności od ustawienia zworek JP1...JP4, tak jak opisano w powyższej tabeli.
Zworki są umieszczone na dolnej stronie płytki modułu, co dokładnie obrazuje poniższy rysunek. Domyślnie połączone są zworki JP1 i JP3. W przypadku zmiany konfiguracji należy rozciąć połączone zworki i połączyć odpowiednie zworki za pomocą lutownicy i kropli spoiwa lutowniczego.

Konfiguracja trybu pracy RS485
| Sygnał | Funkcja | |
|---|---|---|
| RS1 DE | Sygnał sterujący transceiverem interfejsu RS485-1 | |
| Domyślnie aktywne jest automatyczne sterowanie sygnałem TXD | Zwarta zwora JP8 | |
| Opcjonalnie możliwe jest sterowanie sygnałem RTS | Zwarta zwora JP7 | |
| RS2 DE | Sygnał sterujący transceiverem interfejsu RS485-2 | |
| Domyślnie aktywne jest automatyczne sterowanie sygnałem TXD | Zwarta zwora JP10 | |
| Opcjonalnie możliwe jest sterowanie sygnałem RTS | Zwarta zwora JP9 | |
Transceivery interfejsów RS485 wymagają sygnału sterującego nadajnikiem magistrali -aktywującego tryb nadawania. Sygnał sterujący może być uzyskiwany z sygnału danych wysyłanych na magistralę - TXD, lub może być doprowadzany niezależnie – poprzez stan linii RTS. Moduł KAmod RPI 485&CAN Hat pozwala na wybranie jednej z tych opcji dla każdego z interfejsów RS485-1 i RS485-2, poprzez ustawienie zworek JP7...JP10, tak jak opisano w powyższej tabeli.
Zworki są umieszczone na dolnej stronie płytki modułu, co dokładnie obrazuje poniższy rysunek. Domyślnie połączone są zworki JP8 i JP10 – tryb automatyczny dla obu interfejsów. W przypadku zmiany konfiguracji należy rozciąć połączone zworki i połączyć odpowiednie zworki za pomocą lutownicy i kropli spoiwa lutowniczego.

Wymiary
Wymiary płytki KAmod RPI 485&CAN Hat to 65x56 mm. Wysokość płytki to ok. 15 mm, dodatkowo złącze na dolnej stronie płytki, pasujące do płytki bazowej, ma wysokość ok 13 mm.

Uruchomienie
Uruchamiamy Raspberry Pi 5 z systemem operacyjnym zainstalowanym na karcie pamięci lub innym, nośniku. Po wyświetleniu pulpitu systemu otwieramy okno konsoli (Terminal) np. za pomocą kombinacji klawiszy Ctrl+Alt+T i wpisujemy:
sudo nano /boot/firmware/config.txt
(we wcześniejszych wersjach systemu operacyjnego plik config.txt był umieszczony bezpośrednio w katalogu /boot)
W pliku, którego treść zobaczymy, należy usunąć komentarz (usunąć znak #) z linii:
dtparam=spi=on
Natomiast, jeżeli takiej linii nie ma to należy ją dopisać.

Następnie na końcu pliku (przewijamy strzałkami do samego dołu) należy dopisać linie:
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25,spimaxfrequency=10000000
oraz
dtoverlay=sc16is752-spi1,int_pin=24

Następnie należy zapisać zmiany za pomocą klawiszy Ctrl+O, zamknąć edytor za pomocą klawiszy Ctrl+X i uruchomić system ponownie, np. wpisując polecenie:
sudo reboot
Po wyświetleniu pulpitu systemu otwieramy okno konsoli (Terminal) np. za pomocą kombinacji klawiszy Ctrl+Alt+T i wpisujemy:
sudo dmesg | grep -i spi
Jeśli wcześniejsze etapy zostały wykonane prawidłowo powinno pokazać się takie podsumowanie:

Oznacza to, że zarówno kontroler SC16IS762, jak i MCP2515 zostały prawidłowo zainstalowane w systemie.
Przetestowanie interfejsu CAN wymaga wpisania 3 komend:
sudo ip link set can0 up type can bitrate 1000000 sudo ifconfig can0 up cansend can0 000#11.22.33.44
Powinna migać dioda LED D10 sygnalizująca aktywność na magistrali CAN.
Interfejsy RS485 można przetestować z użyciem programu minicom, dla RS485-1 należy wpisać:
minicom -D /dev/ttySC0
natomiast dla RS485-2 należy wpisać:
minicom -D /dev/ttySC1
Program minicom pozwala wysyłać znaki wpisywane z klawiatury oraz wyświetla znaki odebrane przez wybrany interfejs RS485. W czasie aktywności interfejsów będą migały diody D5/D7, ale przy znacznych prędkościach transmisji, np. 115200, miganie diod LED będzie ledwo zauważalne.