[[File:Slotmachine_mcu_diagram.png|1000px|left|mcu serial diagram]]

[[File:Image (2).png|500px|left|debug polarity]] ==Communication Protocol - /dev/ttyS4 (English)== Facing up the PCBA, we can see the Renesas MCU, the PCBA has 4 serial ports + 1 GPIO port at the left hand side of the board. Slot machine connects to the first one (top left), card reader connects to the second one. can === Communication protocol between MCU and host computer (little endian mode) === ====Physical layer protocol==== *Communicate through serial port, baud rate 115200, check bit None, data bits 8, stop bit 1 bits ====Frame format table==== {| class="wikitable sortable" |- ! Start bit !! Data bit !! Check position !! End position |- |0xA5, one byte length||See data bit table, variable length||CRC check of data bits (from the beginning of the data bit to the end of the data bit), 2 bytes in length, low bit first, high bit last|| 0x5A, one byte length |} =====Data bit table===== {| class="wikitable sortable" |- ! Data source address !! Destination address !! Frame sequence number !! Data length (bits 5-6) !! Data command and data content |- |0x01 represents the first CPU board, 0x02 represents the second CPU board, 0x03 represents the third CPU board,'''Currently there is only one RK3568 CPU board, and only 0x01''' is used;
'''0x81 Represents the power charging control board'''', one byte||0x01 represents the first CPU board, 0x02 represents the second CPU board, 0x03 represents the third CPU board'''Currently there is only one RK3568 CPU board, only used 0x01''';
0x81 indicates the power charging control board''';
0x80 indicates that the destination address is broadcast to all CPU circuit boards, 0xfe indicates that the destination address is all RA2E1 circuit boards, 0xff indicates that it is broadcast to the system All devices in it, other addresses are reserved, one byte length || Each time the active data sending device sends data, add one, two bytes, low bit first, high bit last (greater than 0xffff, cleared), receiving needs to return the same data Data return||Data command and data content part data length, two bytes, low byte first, high byte last||See data command and data content table, variable length |} ==== Data command and data content table ==== {| class="wikitable sortable" |- ! Command sequence number (fixed length, two bytes low in the front, high in the back), the 7-8 bits!! Command content (variable length, 0 to n bytes), starting with the 9th digit!! Do you need a reply (fixed length, 1 byte) |- |1, CPU sends heartbeat||None||1 means return is required, 0 means no return is required |- |2, RA2E1 responds to the heartbeat ||0 (no data is received for more than 1 minute, RA2E1 restarts the CPU) ||0 means no need to return |- |3, CPU reads RA2E1 hardware version||Data length 0|1 means return is required, 0 means no need to return |- |4, RA2E1 responds to upload the hardware version || For example, "NT2109A2", 8 bytes in length || 0 means no need to return |- |5, CPU reads RA2E1 software version||None||1 means return is required, 0 means no return is required |- |6, RA2E1 responds to upload software version || For example, "RA2E1211214001", 14 bytes in length || 0 means no need to return |- |7, RA2E1 reporting status|| Battery voltage (2 bytes, low byte first, high byte last, unit mV); charger interface voltage (2 bytes, low byte first, high byte last, unit mV); Original battery current (2 bytes, the obtained value minus 10000, unit mA), calibrated battery current (2 bytes, the obtained value minus 10000, unit mA); system time (year, month, day , hours, minutes, seconds, days of the week (two bytes for the year, the remaining 1 byte, and one 8 bytes)); RTC status (1 byte, 0 means RTC is normal, 1, RTC initialization is abnormal, 2, No second interrupt, 3, no minute interrupt); board temperature, one byte length, actual temperature +40, for example: 20 means -20℃, 60 means 20℃||1 means return is required, 0 means no need to return |- |8, CP reply||None||1 means return is required, 0 means no return is required |- |129, CPU sends upgrade MCU firmware command || ||1 means return is required, 0 means no need to return |- |130, RA2E1U response || One byte, 0, means normal, other means error (when normal, the MCU will send a request to shut down the command. When a response is received or a timeout occurs, the CPU power is disconnected, and the MCU restarts to enter the bootloader. Enter the upgrade process) ||0 means no need to return |- |146, MCU response || One byte, 0, indicates normal, others indicate error || 0 indicates no need to return |- |153, MCU reports OTA information||See MCU reporting OTA information table||0 means no need to return |- |155, send control command to the card reader||65 bytes, the 65th byte is the number of valid bytes, and the 64th byte is the port number||1 means return is required, 0 means no need to return |- |157, MCU response||The specific data depends on the data returned by the card reader||0 means no need to return |- |161, CPU sends (modify the timeout time of UART9) || Two bytes, modify the timeout time of UART9 (unit: seconds) For example: 0x00 0x0F, means 15 seconds || 1 means return is required, 0 means no need to return |- |162, MCU response|| One byte, 0, means normal ||0 means no need to return |- |163, CPU sends (calibration coulomb meter current)|| Four bytes, calibrate coulomb meter current (unit: ma). The first two bytes represent the current current of the mcu, and the last two bytes are the current current of the ammeter (the low bit is in front, high bit after) ||1 means return is required, 0 means no need to return |- |164, MCU response || One byte, 0, indicates normal, others indicate error || 0 indicates no need to return |- |165, sent by CPU (clear battery history parameters)|| One byte: 0x01||1 means return is required, 0 means no need to return |- |166, MCU response|| One byte, 0, means normal, other means error ||0 means no need to return |- |167, CPU sends (test uart3)|| One byte: 0x01||1 indicates the need to return |- |168, MCU response || 1 byte, 0, means normal, 1 means uart3 exception || 0 means no need to return |- |169, CPU sends (test uart4)|| One byte: 0x01||1 indicates the need to return |- |170, MCU response || 1 byte, 0, means normal, 1 means uart4 exception || 0 means no need to return |} ====MCU reports OTA information table==== {| class="wikitable sortable" |- |0x01,0x02,0x03,3 bytes (failed to open flash driver) |- |0x04,0x05,0x06,3 bytes (whether forced upgrade is required? When receiving this data, enter 0x38 within 5 seconds to upgrade GPS, 0x39 to upgrade RFID, and exit if not entered within 5 seconds) |- |0x07,0x08,0x09,3 bytes (prepare to forcefully upgrade the GPS board) |- |0x0A, 0x0B, 0x0C, 3 bytes (preparing for forced upgrade of RFID board) |- |0x0D,0x0E,0x0F,3 bytes (RFID preparation timeout) |- |0x10,0x11,0x12,3 bytes (timeout for receiving RFID response data) |- |0x13,0x14,0x15,3 bytes (RFID OTA successful) |- |0x16,0x17,0x18,3 bytes (RFID OTA failed) |- |0x19, 0x1A, 0x1B, 3 bytes (possible: the RFID board is disconnected and the file upload fails; processing method: wait for rfid to enter the main program (about 20s), or restart the RFID board) |- |0x1C, 0x1D, 0x1E, 3 bytes (no RFID reply received, wait for the RFID board to enter the main program (about 20s) before trying again) |- |0x1F,0x20,0x21,3 bytes (RFID response timed out, please try again) |- |0x22, 0x23, 0x24, 3 bytes (after receiving this command within 5 seconds, send 0x32 to the mcu and start preparing for the GPS board ota) |- |0x37,0x38,0x39,3 bytes (check app area) |- |0x25,0x26,0x27,3 bytes (you can start transferring the bin file that needs to be upgraded after receiving this command) |- |0x28,0x29,0x2A,3 bytes (upgrade successful) |- |0x2B,0x2C,0x2D,3 bytes (upgrade failed: Flash address is invalid) |- |0x2E,0x2F,0x30,3 bytes (upgrade failed: download timeout) |- |0x31,0x32,0x33,3 bytes (upgrade failed: Flash error) |- |0x34,0x35,0x36,3 bytes (upgrade failed: unknown error) |- |0x40,0x41,0x42,3 bytes (waiting for "0x32" timeout) |} ==Communication Protocol - Uart9== === Communication protocol between MCU and host computer (little endian mode) === ====Physical layer protocol==== *Communicate through serial port, baud rate 115200, check bit None, data bits 8, stop bit 1 >> bits *Uart9 corresponds to 9bit device, without any protocol encapsulation, raw data. ==Examples== *Slot sent: 01 44, ttyS3 received: 01 44 (no processing done). *ttyS3 sends: 01 44, slot machine receives: 01 44 (no processing is done). *Sent on ttyS4: A5 01 81 00 00 03 00 05 00 01 5B 0D 5A (query the mcu version number), ttyS4 receives: A5 81 01 00 00 11 00 06 00 52 41 34 4D 32 32 33 31 31 32 33 30 30 30 00 F9 C9 5A, of which 00 52 41 34 4D 32 32 33 31 31 32 33 30 30 30 indicates the mcu that has been parsed version number. *Sent on ttyS4: A5 01 81 00 00 44 00 9B 00 02 00 02 B1 00 B3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 01 79 8A 5A (read magnetic card information), ttyS4 received: A5 81 01 00 00 3A 00 9D 00 02 00 33 00 80 59 56 32 59 49 4C 49 4E 47 20 20 20 20 30 30 32 38 33 31 39 35 33 31 30 38 30 32 81 59 30 30 32 38 3 3 31 39 35 33 31 30 38 30 32 30 30 30 82 4E E3 55 00 42 2F 5A, of which 00 02 00 33 00 80 59 56 32 59 49 4C 49 4E 47 20 20 20 20 30 30 32 38 33 31 39 35 33 31 3 0 38 30 32 81 59 30 30 32 38 33 31 39 35 33 31 30 38 30 32 30 30 30 82 4E E3 55 (indicates the specific information of the magnetic card that has been parsed). ====PCB user indication LED explanation==== *LED1 (LED under PCB) **Flashing every 200ms indicates entering the mcu upgrade mode. **Constant indicates that the MCU has been powered on. *LED2 (LED on PCB) **Flashing every 250ms indicates entering MPU burn-in mode. **Irregular flashing indicates that the communication between MCU and MPU is normal. ==How to enter the flashing mode== #The white button is the Recovery Key. #The USB port at the bottom is in slave mode by default and is used to burn the system image file. [[File:slotmachine_flash_1.png|500px|]] ====Steps==== *Press and hold the Recovery Key, then insert the power source. [[File:slotmachine_flash_2.png|500px|]] *wait until the LED indicator light starts blinking. [[File:slotmachine_flash_3.png|500px|]] *Plug in the USB cable [[File:slotmachine_flash_4.png|500px|]] *a "Maskrom" device will be detected on the PC [[File:slotmachine_flash_6.png|500px|]] the steps to update the unified firmware update.img are as follows: ##Switch to the Upgrade Firmware page. ##Press the Firmware button to open the firmware file to be upgraded. The upgrade tool displays detailed firmware information. ##Press the Upgrade button to start the upgrade. == 通讯协议-Uart0(Chinese)== === MCU 与 上位机通讯协议(小端模式) === ====物理层协议==== *通过串口通讯,115200波特率,校验位None,数据位8位,停止位1位 ====帧格式表==== {| class="wikitable sortable" |- ! 起始位 !! 数据位 !! 校验位置 !! 结束位置 |- |0xA5,一个字节长度||见数据位表,变长||数据位(从数据位开始到数据位结束)的CRC校验,2个字节长度,低位在前,高位在后||0x5A,一个字节长度 |} =====数据位表===== {| class="wikitable sortable" |- ! 数据来源地址 !! 目的地址 !! 帧序号 !! 数据长度 (第5-6位) !! 数据命令以及数据内容 |- |0x01表示第一块CPU板,0x02表示第二块CPU板,0x03表示第三块CPU板,'''目前只有一块RK3568 CPU 板子,只用到0x01''';
'''0x81表示 电源充电控制板''',一个字节||0x01表示第一块CPU板,0x02表示第二块CPU板,0x03表示第三块CPU板'''目前只有一块RK3568 CPU 板子,只用到0x01''';
0x81表示 电源充电控制板''';
0x80表示目的地址是广播给所有的CPU电路板,0xfe表示目的地址是所有的RA2E1电路板,0xff表示广播给系统中所有设备,其他地址备用,一个字节长度||主动发送数据设备每发送一次数据加一个,两个字节,低位在前,高位在后(大于0xffff,清零),接收需要返回数据同数据返回||数据命令以及数据内容部分数据长度,两个字节,低位在前,高位在后||见数据命令以及数据内容表,变长 |} ====数据命令以及数据内容表==== {| class="wikitable sortable" |- ! 命令序号(定长,两个字节低位在前,高位在后),第7-8位 !! 命令内容(变长,0到n个字节),第9位开始 !! 是否需要回复(定长,1个字节) |- |1,CPU发送心跳||无||1表示需要返回,0表示无需返回 |- |2,RA2E1应答心跳||0(超过1分钟没有收到任何数据,RA2E1重启CPU)||0表示无需返回 |- |3,CPU读取RA2E1硬件版本||数据长度0|1表示需要返回,0表示无需返回 |- |4,RA2E1应答上传硬件版本||例如,"NT2109A2",8个字节长度||0表示无需返回 |- |5,CPU读取RA2E1软件版本||无||1表示需要返回,0表示无需返回 |- |6,RA2E1应答上传软件版本||例如,"RA2E1211214001",14个字节长度||0表示无需返回 |- |7,RA2E1上报状态|| 电池电压(2个字节,低位在前,高位在后,单位mV);充电器接口电压(2个字节,低位在前,高位在后,单位mV);原始电池电流(2个字节,得到的值减去10000,单位mA),校准过的电池电流(2个字节,得到的值减去10000,单位mA);系统时间(年、月、日、时、分、秒、礼拜(年两个字节,其余1个字节,一个8个字节)); RTC状态(1个字节,0表示RTC正常,1,RTC初始化异常,2,没有秒中断,3,没有分钟中断);板子温度,一个字节长度,实际温度+40,比如:20表示,-20℃,60表示20℃||1表示需要返回,0表示无需返回 |- |8,CP回复||无||1表示需要返回,0表示无需返回 |- |129,CPU发送升级MCU固件指令|| ||1表示需要返回,0表示无需返回 |- |130,RA2E1U应答||一个字节,0,表示正常,其他表示错误(正常时,MCU会发送请求关机指令,收到应答或者超时情况下,断开CPU电,并MCU重启,进入bootloader,进入升级流程)||0表示无需返回 |- |153,MCU上报OTA信息||见MCU上报OTA信息表||0表示不需要返回 |- |155,发送控制命令给读卡器||65个字节,第65个字节是有效字节数量、64个字节是端口号||1表示需要返回,0表示无需返回 |- |157,MCU应答||具体数据根据读卡器返回的数据而定||0表示无需返回 |- |161,CPU发送(修改UART9的超时时间)||两个字节,修改UART9的超时时间(单位:秒)例如:0x00 0x0F,表示15秒||1表示需要返回,0表示无需返回 |- |162,MCU应答|| 一个字节,0,表示正常 ||0表示无需返回 |- |163,CPU发送(校准库仑计电流)||四个字节,校准库仑计电流(单位:ma)前面两个字节代表mcu当前电流,后面两个字节是电流表的当前电流(低位在前,高位在后)||1表示需要返回,0表示无需返回 |- |164,MCU应答|| 一个字节,0,表示正常,其他表示错误 ||0表示无需返回 |- |165,CPU发送(清空电池历史参数)|| 一个字节:0x01||1表示需要返回,0表示无需返回 |- |166,MCU应答|| 一个字节,0,表示正常,其他表示错误 ||0表示无需返回 |- |167,CPU发送(测试uart3)|| 一个字节:0x01||1表示需要返回 |- |168,MCU应答|| 1个字节,0,表示正常,1表示uart3异常||0表示无需返回 |- |169,CPU发送(测试uart4)|| 一个字节:0x01||1表示需要返回 |- |170,MCU应答|| 1个字节,0,表示正常,1表示uart4异常||0表示无需返回 |} ====MCU上报OTA信息表==== {| class="wikitable sortable" |- |0x01,0x02,0x03,3个字节(打开flash驱动失败) |- |0x04,0x05,0x06,3个字节(是否需要强制升级,在接收到这条数据时5s内输入0x38则升级GPS,0x39则升级RFID,5s内不输入则退出) |- |0x07,0x08,0x09,3个字节(准备强制升级GPS板子) |- |0x0A,0x0B,0x0C,3个字节(准备强制升级RFID板子) |- |0x0D,0x0E,0x0F,3个字节(RFID准备超时) |- |0x10,0x11,0x12,3个字节(接收RFID应答数据超时) |- |0x13,0x14,0x15,3个字节(RFID OTA成功) |- |0x16,0x17,0x18,3个字节(RFID OTA失败) |- |0x19,0x1A,0x1B,3个字节(有可能:RFID板子断开连接、上传文件失败;处理方法:等待rfid进入主程序(大概20s),或者重启RFID板子) |- |0x1C,0x1D,0x1E,3个字节(没有收到RFID回复,等待RFID板子进入主程序(大概20s)再重新尝试) |- |0x1F,0x20,0x21,3个字节(RFID应答超时,请重新尝试) |- |0x22,0x23,0x24,3个字节(5秒内接收到这个命令后向mcu发送0x32就开始准备给GPS板子ota了) |- |0x37,0x38,0x39,3个字节(检查app区域) |- |0x25,0x26,0x27,3个字节(接收到这个命令就可以开始传输需要升级的bin文件了) |- |0x28,0x29,0x2A,3个字节(升级成功) |- |0x2B,0x2C,0x2D,3个字节(升级失败:Flash地址无效) |- |0x2E,0x2F,0x30,3个字节(升级失败:下载超时) |- |0x31,0x32,0x33,3个字节(升级失败:Flash错误) |- |0x34,0x35,0x36,3个字节(升级失败:未知错误) |- |0x40,0x41,0x42,3个字节(等待"0x32"超时) |} ====PCB用户指示LED解释==== *LED1(PCB下面的LED) **每间隔200ms闪烁说明进入mcu升级模式。 **常量表示MCU已经上电。 *LED2(PCB上面的LED) **每间隔250ms闪烁说明进入MPU烧入模式。 **不规则闪烁说明MCU和MPU通讯正常。 ==通讯协议-Uart9== === MCU与上位机通讯协议(little endian模式) === ====物理层协议==== *通过串口通讯,波特率115200,校验位,数据位8,停止位1> > 位 *Uart9对应9bit设备,无任何协议封装,原始数据。 ==通讯协议解释== *老虎机发送:01 44,ttyS3收到:01 44(不做任何处理)。 *ttyS3发送:01 44,老虎机收到:01 44(不做任何处理)。 *在ttyS4发送:A5 01 81 00 00 03 00 05 00 01 5B 0D 5A(查询mcu版本号),ttyS4收到: A5 81 01 00 00 11 00 06 00 52 41 34 4D 32 32 33 31 31 32 33 30 30 30 00 F9 C9 5A,其中00 52 41 34 4D 32 32 33 31 31 32 33 30 30 30表示已经解析完成的mcu版本号。 *在ttyS4发送:A5 01 81 00 00 44 00 9B 00 02 00 02 B1 00 B3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 01 79 8A 5A(读磁卡信息),ttyS4收到:A5 81 01 00 00 3A 00 9D 00 02 00 33 00 80 59 56 32 59 49 4C 49 4E 47 20 20 20 20 30 30 32 38 33 31 39 35 33 31 30 38 30 32 81 59 30 30 32 38 33 31 39 35 33 31 30 38 30 32 30 30 30 82 4E E3 55 00 42 2F 5A,其中00 02 00 33 00 80 59 56 32 59 49 4C 49 4E 47 20 20 20 20 30 30 32 38 33 31 39 35 33 31 30 38 30 32 81 59 30 30 32 38 33 31 39 35 33 31 30 38 30 32 30 30 30 82 4E E3 55(表示已经解析完成的磁卡具体信息)。