📜 ⬆️ ⬇️

The implementation of the protocol MIL-STD-1553 on STM32

Once, there was a need to use a multiplex information exchange channel (MKIO) in our device, it’s also GOST R 52070-2003, aka MIL-STD-1553B. The initial search result was somewhat surprising: typical solutions issued by the search engine, as a rule, were based on the use of FPGAs. Since the problem had to be solved quickly, the thought appeared to make a protocol converter from MIL-STD-1553 to MODBUS RTU. At the same time, try to use fairly inexpensive technical solutions and a microcontroller from the STM32 family.



In the photo from Wikipedia: F16, on which the tire MIL-STD-1553B was first used. Our devices do not fly :), so there are no restrictions on the use of the element base. Just at the customer's instrument network is built on the basis of this bus. The first part of the article describes the reception and transmission on the bus of the MKIO, the second part will be about the converter to MODBUS.

The first stage of any development: finding information and reading documentation. After this stage, the following happened in my head:
')
- the protocol is quite simple :)
- the maximum frame is 32 bytes :)
- has a pretty hard timing: (
- quite expensive chips and modules: (

After some reflections I stopped using the HOLT decoder HI-15530 decoder, but there are quite a few analogs of this chip. True, not everyone can be available in Russia for reasonable money and time. :)

Here is an approximate scheme of the inclusion of this chip. The truth is taken from the analog datasheet. :)



Then everything is simple :) We connect 16 bit data buses to the microprocessor ports: PARALLEL IN and PARALLEL OUT and control signals:

- VALID WORD (Accepted word is correct)
- ENCODER ENABLE (Start word transfer)
- COMMAND SYNC (Select command / data)

Instead of register 74LS164, we had to use the analogue EKF1533IR8. In addition, SN74ALS1035 (EKF1533LP17) open collector repeaters are used to match 3.3V (STM32) signals to 5V (HI-15530).

After some correspondence with manufacturers and suppliers, the EL-15N transceiver from ELKUS was selected.



Added another ST control signal (Transmitter power up)

It turned out such a fee.



Started debugging software. To simulate the exchange of data with the channel, a USB module was purchased from the Module company, which can be either a terminal device (OU) or a bus controller (CS).



The PURUMK control program is attached to the module. The program of reception and transmission was quite simple.

Reception of a 16-bit word occurs by interruption from the VALID WORD signal:

void EXTI9_5_IRQHandler (void) //Valid Word { Ctrl_LED3_ON EXTI->PR|=0x0040; //  STD1553_RX_buffer[recieve_count] = GPIOE->IDR; recieve_count++; frame_from_channel = 1; //   Ctrl_LED3_OFF } 

Handling of the received word flag:

  if (frame_from_channel) { frame_from_channel = 0; switch (Channel_state) { case 0: //   Device_address_recieved = STD1553_RX_buffer[0]; Device_address_recieved = Device_address_recieved >> 11; if (Device_address_recieved == Device_address) //   { Command_recieved = STD1553_RX_buffer[0]; //    Command_recieved = Command_recieved & 0x001F; // /  Transmitt_direction = STD1553_RX_buffer[0]; Transmitt_direction = Transmitt_direction & 0x0400; if (Transmitt_direction == 0x0400) //    { TRANSMITTER_ENABLE_HIGH; //    TIM5->CR1 |= TIM_CR1_CEN; //Bit 0 CEN: Counter enable TIM5->CNT = Transmitt_word_period; // Answer_word_flag = 1; } else //    { Channel_state = 1; } } else { recieve_count = 0; } break; case 1: //  if (recieve_count == Command_recieved + 1) { //   TRANSMITTER_ENABLE_HIGH; Answer_word_flag = 1; Command_recieved = 0; //  TIM5->CR1 |= TIM_CR1_CEN; //Bit 0 CEN: Counter enable TIM5->CNT = Transmitt_word_period; // } break; } //end of switch } //end of if 

And the actual transfer of data to the channel. Each word is transmitted to the channel by interrupting the timer.

 //    void TIM5_IRQHandler (void) // { EXTI->IMR &= ~EXTI_IMR_MR6; //DISABLE Interrupt Mask on line 1 if (Answer_word_flag) { SYNC_SELECT_COMMAND; Answer_word_flag = 0; } else { SYNC_SELECT_DATA; } GPIOD->ODR = STD1553_TX_buffer[transmitt_count]; delay(5); ENCODER_ENABLE_HIGH; //    delay(112); transmitt_count ++; ENCODER_ENABLE_LOW; //     if (transmitt_count > Command_recieved) { delay(700); TIM5->CR1 &= ~TIM_CR1_CEN; //Bit 0 CEN: Counter enable transmitt_count = 0; EXTI->IMR |= EXTI_IMR_MR6; //ENABLE Interrupt Mask on line 1 Channel_state = 0; recieve_count = 0; TRANSMITTER_ENABLE_LOW; } TIM5->SR = 0; TIM5->CNT = 0; } 

And here is the result.



Abbreviations OUKSH and KSOU mean, respectively: terminal device - bus controller, bus controller - terminal device. That is, in the first case, a request for data transmission from the OS, and in the second, data transfer to the terminal device. In either case, the word 31 is transmitted. More than 10,000 words are accepted and transmitted and not a single error. :)

Source: https://habr.com/ru/post/316430/


All Articles