понедельник, 12 июня 2017 г.

1-Wire & GPIO firmware; main board project

STM32F100/103 W1 module

In the previous message, it was described how to work with CAN-bus.

A sufficiently large number of modules have already been manufactured.
To begin with, consider module W1.
Types of sensors which can connected to the module:

View of the module without housing.

 
Detail Work with W1 firmware
"W1" firmware, Gerber PCB and scheme W1 board

суббота, 27 мая 2017 г.

Explore CAN-bus with stm32f100 board

CAN Interface

A Controller Area Network (CAN bus) is a vehicle bus standard designed to allow microcontrollers and devices to communicate with each other in applications without a host computer. It is a message-based protocol, designed originally for multiplex electrical wiring within automobiles, but is also used in many other contexts.

Architecture

CAN is a multi-master serial bus standard for connecting Electronic Control Units [ECUs] also known as nodes. Two or more nodes are required on the CAN network to communicate. The complexity of the node can range from a simple I/O device up to an embedded computer with a CAN interface and sophisticated software. The node may also be a gateway allowing a standard computer to communicate over a USB or Ethernet port to the devices on a CAN network.


All nodes are connected to each other through a two wire bus. The wires are 120 Ohm nominal twisted pair.

To work with CAN suitable twisted pair category 5e.
For example:
CAN-L - orange light
CAN-H - orange dark.
Other wires can use for power suplay ( 9-24V ).

Maximum Cable Length For a CAN Bus: 


For communicate between modules use extended frame format.
The description details of format see below.

For CAN, the extended format of the data frame is used.
4 bytes - identifier, 8 bytes - data.
The first byte of the CAN frame can be a maximum of 1F

Bit identifier format:

The extended format of the data frame is used.
Extended CAN ID format:

Protocol of CAN ( Only Extended frame format ):

For CAN, the extended format of the data frame is used.
4 bytes - identifier, 8 bytes - data.
The first byte of the CAN frame can be a maximum of 1F

Bit identifier format:

The extended format of the data frame is used.
Extended CAN ID format:

Protocol of CAN ( Only Extended frame format ):

can0    400200  [8] 00 00 00 00 00 00 00 00 - Request for data with device number 4
can0    400280  [8] 07 00 00 00 00 00 00 00 - Answer device number 4

can0    400100  [8] 07 00 00 00 00 00 00 00 - Transferring data to device number 4

can0    400180  [8] 07 00 00 00 00 00 00 00 - Answer device number 4 (current status)

can0    100200  [1] 00                      - Request for data with device number 1 (one byte)

can0    100280  [8] 00 00 00 00 00 00 00 00 - Answer device number 1

can0    100100  [1] FF                      - Sending data to the device with number 1 (one byte)

can0    100180  [8] FF 00 00 00 00 00 00 00 - Answer device number 1 (current status)

can0    100F00  [1] 00                      - Sending data to the device with number 1 (one byte)

can0    108F80  [8] 00 00 00 00 00 00 00 00 - Answer device number 1 ( error, wrong command )

The device always responds to packets addressed to it. This is a confirmation of receipt of the package.

Address=0 - Broadcast distribution.

Examples ( Linux candump ):

can0    400200  [8] 00 00 00 00 00 00 00 00 - Request for data with device number 4
can0    400280  [8] 07 00 00 00 00 00 00 00 - Answer device number 4

can0    400100  [8] 07 00 00 00 00 00 00 00 - Transferring data to device number 4
can0    400180  [8] 07 00 00 00 00 00 00 00 - Answer device number 4 (current status)

can0    100200  [1] 00                      - Request for data with device number 1 (one byte)
can0    100280  [8] 00 00 00 00 00 00 00 00 - Answer device number 1

can0    100100  [1] FF                      - Sending data to the device with number 1 (one byte)
can0    100180  [8] FF 00 00 00 00 00 00 00 - Answer device number 1 (current status)

can0    100F00  [1] 00                      - Sending data to the device with number 1 (one byte)
can0    108F80  [8] 00 00 00 00 00 00 00 00 - Answer device number 1 ( error, wrong command )

Each device has a unique serial number Sn (4 bytes) and Id, or device type (4 bytes)

Broadcasting commands ( CAN address = 0 ):

C1:C2
C1 - Command ( function code )
C2 - Command expansion ( function code 2 )
------------------------------------------------------------------------------
2:x - Request for data
2:0 - To get serial number; the device will return the first 4 bytes of Sn.
      In the next 4 bytes the device code (identifier)
2:1 - Get CAN number; In the first 4 bytes of Sn, to whom is addressed.

1:x - Setting values
1:1 - Do not to respond for a broadcast serial number request.
      In the first 4 bytes of Sn, to whom is addressed.
1:2 - Set CAN number
      In the first 4 bytes of Sn, to whom is addressed
      5th byte is a number of CAN

Consider a simple network of two controllers STM32F100 ( STM32F100 board )
In addition, you will need two USB-UART adapters.
Scheme and PCB board
Download firmware CAN-Gate to MicroController ( source, hex, bin ).
This firmware can be used as a template for your own programs.
Size of program is 12KB, and you can use KEIL as free-evalution mode (up to 16K).
KEIL project in archve.

Open two terraterm of the program.
In our example, COM14 and COM30 and research work of CAN-bus.
Terminal-program, current speed is 921600 bps