Skip to content
Snippets Groups Projects
Forked from latex / Beamer TPT NG
Source project has a limited visibility.

Hardware

Board DC Motor Driver Hat DFRobot DFR0592

Microcontroller STM32F103C8T6 (medium density)

Useful onboard peripherals

Peripheral N
Flash 64kiB
RAM 20kiB
Timers (general purpose) 3
Timers (advanced control) 1
CPU frequency 72MHz
I2C 2

The I2C2 is used (PB10=/=SCL, PB11=/=SDA) to communicate with the TB6612FNG motor driver.

Flash-memory organization

  • Main memory: 64 pages of 1KiB
  • Page erasable
  • Programmable by half-words
  • VTOR must be aligned with the number of exception entries or 128 bits, whichever is largest. To use all DMA channels (DMA2_Channel4_5 is at position 59), an alignment of 256 is required. In any case, aligning it on a page boundary will work.

Driver IC TB6612FNG for dual DC motor

Encoders FIT0450

Led pattern

The led pattern is in Morse code.

Code Meaning Pattern
I Regular mode ..
LP Low power (Vdd is below 2.9V) .-.. .–.
WW Last reset was due to the window watchdog trigerring .– .–

Command set

Multibyte values are exchanged in little endian format.

[IMPLEMENTED] 0x08 Firmware version (R)

  • Return three bytes containing the major, minor and patch version numbers derived from Cargo.toml.

[IMPLEMENTED] 0x0F Who am I? (R)

  • The I²C address

0x10 [IMPLEMENTED] PWM frequency (R/W)

  • Frequency in Hz on 3 bytes, from 1 to 100_000 (default: 10_000)

[IMPLEMENTED] 0x11 Max motor percentage (R/W)

  • Limit the maximum speed, between 1% and 100% of the duty cycle (default: 100)

0x14 Encoder to motor reduction (R/W)

  • Between 1 and 255. 0 disable encoder control (default 0)

0x20-0x25 PID coefficients (R/W)

  • P, I, and D between -327.68 and 327.67. Default values are P=1.0, I=0.0, D=0.0
  • In order, each on 2 bytes, signed: 100×P, 100×I, 100×D
  • Result is capped by the maximum motor value (max values for the motor)

0x26 Ramp time (R/W)

  • In automatic motor distance, time in 100th of seconds to reach the maximum speed or to decrease the speed from the maximum to 0.

[IMPLEMENTED] 0x28 Motor shutdown timeout (R/W)

  • Number of tenths of seconds in before the motor shut down. The minimum is 1 (0.1 seconds) and the maximum is 100 (10 seconds).

[IMPLEMENTED] 0x30-0x31 Motor speed (R/W)

  • Left and right motor speed, between -127 and 127 each, max speed is ±127. -128 means standby. ±127 corresponds to the value limited by the max motor percentage.
  • If written while in automatic mode, the robot switches to manual mode

[IMPLEMENTED] 0x32-0x35 Encoder ticks (R)

  • Left and right encoder counters since last time, 2 complement, 2 bytes each

[IMPLEMENTED] 0x36 Status (R)

  • Bit 0: moving (1) or idle (0)

0x37-0x3A Automatic motor distance (R/W) [optional]

  • Left and right distance in number of encoder ticks, between -32768 and 32767 each.
  • Reading this value gives the distance to the target in ticks.
  • If left and right distances are not equal, they will be kept proportional as much as possible in order to progress the same way.

0x40-0x43 Music (W) [optional]

  • For each motor, left then right, frequency in Hz on 1 byte and duration in 10th of seconds on 1 byte. This cannot be used if the motor is moving.

0xF0-0xF7 Unique device ID (R)

  • Unique device ID as found in addresses 0x1FFFF7E8-0x1FFFF7EF

0xFE Firmware capabilities (R)

  • Bit 0: automatic motor mode is activated
  • Bit 1: music feature is activated
  • Bit 2: bootloader feature is activated

0xFF Special features (R/W)

Special features can be activated or deactivated by writing a variable-length byte sequence in one I²C write operation (this address does not auto-increment).

  • [C0 FF EE 01]: enter I²C bootloader (if enabled)
  • [FE FF 10 03]: reset the board (always enabled even after a failure)

The following features can only be used 10 seconds after the board has been reset. In case of a failed command, no other of those feature can be used until the next reset.

  • [AB 07 XX XX XX XX XX]: enable automatic motor mode
  • [BA 71 XX XX XX XX XX]: enable music feature
  • [90 70 XX XX XX XX XX]: enable bootloader

XX values are chose at compile time and the board owner may chose not be publicize them. One value can be tested every 10 seconds at most, needing a mean time of ~174 years to randomly find the right value.

**Note:** those could be dependent on the unique device ID in order to be able to selectively enable those features.

The result of a command can be read as one byte at this address unless the feature executes an alternate firmware.

  • 0x00: success
  • 0x01: failure
  • 0x02: command executed too soon
  • 0x03: features locked because of previous failure