Sterowanie modułu przez UART JQ6500

Rodzina procesorów bogatszych w wiele nowych rozwiązań i dlatego warto po nie sięgnąć.
Awatar użytkownika
Karlos128@nos
Posty: 53
Rejestracja: 18 sie 2015, 13:32

Sterowanie modułu przez UART JQ6500

Post autor: Karlos128@nos » 10 sie 2019, 18:08

Witam, Panowie jak wysłać coś takiego "7E 04 03 00 06 EF" do modułu JQ6500? Musi to być wysłane jako hex.
Wysyłanie z Procesora Xmega384c3
Próbowałem tak:
  1. print #1 , "7E 04 03 00 01 EF"
i nic z tego. A jak wyślę z terminala sscom jako hex to moduł reaguje dobrze.
Może to i proste co dla nie których, ale byłbym wdzięczny za pomoc.
Awatar użytkownika
niveasoft
Posty: 1207
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Sterowanie modułu przez UART JQ6500

Post autor: niveasoft » 10 sie 2019, 21:32

Zadeklaruj tablicę no po komputerowemu "array() :D
Czyli Dim Your_array(10) As Byte ' nie musi byc dycha, ...
Potem nadaj wartosci bajtom
Your_array(1)- &H7E
Your_arra(2)=&H04
...itd
na końcu napisz Printbin #1 , Your_array(1),6
Awatar użytkownika
niveasoft
Posty: 1207
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Sterowanie modułu przez UART JQ6500

Post autor: niveasoft » 10 sie 2019, 21:35

Print zamienia dane na te drukowane ASCII
Printbin to drukuje dokładnie to co chcesz,ale zakłada że wiesz co robisz :D
Awatar użytkownika
Karlos128@nos
Posty: 53
Rejestracja: 18 sie 2015, 13:32

Re: Sterowanie modułu przez UART JQ6500

Post autor: Karlos128@nos » 10 sie 2019, 22:12

No to biorę się do roboty , dzięki.
Właśnie przetestowałem i cacy. Ivonka + ten moduł = gadający procek. Pozdrowionka. :)
Awatar użytkownika
niveasoft
Posty: 1207
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Sterowanie modułu przez UART JQ6500

Post autor: niveasoft » 10 sie 2019, 22:55

Wierzę że jesteś zafascynowany. Chciałbym zebys zerknął na przyszłośc jak mozna rozkminiać odpowiedzi modułu. Tu kilkakrotnie nałożyłem Overlay na bufor danych :P
Na bufor odebranych danych mozna nakładać Overlay wielokrotnie ;)
  1. $regfile = "m2560def.dat"                                   '8K SRAM | 4K EEPROM
  2. $crystal = 16000000
  3. $hwstack = 256
  4. $swstack = 128
  5. $framesize = 256
  6. $baud = 115200
  7. $baud1 = 9600
  8.  
  9. Debug On
  10.  
  11. Config Submode = New
  12.  
  13. Const Max_usb_in_command_len = 50
  14. Const Max_nex_command_len = 50
  15. '*****************************************************************
  16. '*         CONFIG BUFFERED USART FOR DEBUG via USB               *
  17. '*****************************************************************
  18.  
  19. Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
  20.  Echo Off
  21.  
  22.  Config Serialin0 = Buffered , Size = Max_usb_in_command_len       'RX from Terminal
  23.   Dim Char As Byte , Cmd_timeout1 As Byte , Got_str1 As Byte
  24.   Dim Command1 As String * Max_usb_in_command_len
  25.  
  26.  'Config Serialout0 = Buffered , Size = Max_usb_out_command_len       'TX to the Terminal
  27.   Open "COM1:" For Binary As #1
  28.     Const Usb = 1
  29. '*****************************************************************
  30. '*           CONFIG BUFFERED USART FOR NEXTION                   *
  31. '*****************************************************************
  32.  
  33. Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
  34.  
  35.  Config Serialin1 = Buffered , Size = Max_nex_command_len   'RX
  36.   Dim Cmd_timeout As Byte , Got_str As Byte
  37. 'unnecessary
  38.   Dim Command As String * Max_nex_command_len
  39.  
  40.  'Config Serialout1 = Buffered , Size = Max_nex_command_len         'TX
  41.   Open "COM2:" For Binary As #2
  42.    Const Nex = 2
  43.  
  44. '*****************************************************************
  45. '*                TIMER2 FOR TIME BASE                           *
  46. '*****************************************************************
  47. Config Timer2 = Timer , Prescale = 1024 , Compare_a = Disconnect , Compare_b = Disconnect , Clear_timer = 1
  48.  Compare2a = 155                                            '10ms @16MHz/1024
  49.  
  50.  
  51.  
  52. 'BARTek multipurpose
  53. Dim Helpb As Byte , Helpstr As String * 30 , N As Byte , Tempb As Byte , Helpl As Long
  54.  
  55. Enable Interrupts                                           'buffered USART
  56.  
  57. Print #usb , "Program restarted"
  58.  
  59. 'NEXTION RETURN DATA                                        LENGTH
  60. Const Invalid_instruction = &H00                            '4
  61. Const Instruction_okay = &H01                               '4
  62. Const Invalid_component_id = &H02                           '4
  63. Const Invalid_page_id = &H03                                '4
  64. Const Invalid_picture_id = &H04                             '4
  65. Const Invalid_font_id = &H05                                '4
  66. Const Invalid_file_operation = &H06                         '4
  67. Const Invalid_crc = &H09                                    '4
  68. Const Invalid_baud_rate = &H11                              '4
  69. Const Invalid_vaweform_id = &H12                            '4
  70. Const Invalid_variable_name = &H1A                          '4
  71. Const Invalid_variable_operation = &H1B                     '4
  72. Const Assignement_failed = &H1C                             '4
  73. Const Eeprom_operation_failed = &H1D                        '4
  74. Const Invalid_parameters_quantity = &H1E                    '4
  75. Const Io_operation_failed = &H1F                            '4
  76. Const Escape_char_invalid = &H20                            '4
  77. Const Variable_name_to_long = &H23                          '4
  78. 'return codes valid  in all cases
  79. '00 00 00 FF FF FF =>Nextion starup                          '6
  80. Const Serial_buff_overflow = &H24                           '4
  81. Const Touch_event = &H65                                    '7
  82. ' 65 00 01 01 FF FF FF
  83. ' |   |  |  |
  84. ' |   |  |  event 01=press, 00=release
  85. ' |   |  component ID
  86. ' |   page number
  87. ' touch event
  88. Const Curr_page_num = &H66                                  '5 second byte is page num
  89. Const Touch_awake_coordinate = &H67                         '9
  90. Const Touch_sleep_coordinate = &H68
  91.  'first two bytes is X
  92.  'next two bytes is Y
  93.  'last byte is event 01=press, 00=release
  94.  'eg. 67 00 7A 00 1E 01 FF FF FF
  95. Const String_data = &H70                                    'varied len eg.70 xx xx xx xx xx xx FF FF FF
  96. Const Numeric_data = &H71                                   '8 eg.71 xx xx xx xx FF FF FF  <-4bytes 32bit value, little endian
  97. Const Auto_sleep = &H86                                     '4
  98. Const Auto_awake = &H87                                     '4
  99. Const Nextion_ready = &H88                                  '4
  100. Const Micro_sd_upgrade = &H89                               '4
  101. Const Transp_data_finished = &HFD                           '4
  102. Const Transp_data_ready = &HFE                              '4
  103.  
  104. Macro Nexend                                                'to end a tx sequence--------------------------
  105.      Printbin #nex , &HFF ; &HFF ; &HFF
  106. End Macro
  107.  
  108. Macro Nexq                                                  ' to send quote before or after a sentence---------
  109.      Printbin &H22
  110. End Macro
  111.  
  112. Sub Set_return_level()
  113.   'how much return will be sent over serial
  114.   'LEVEL (2 is default)
  115.   '0=no return command will be sent
  116.   '1=only confirm succes commands
  117.   '2=only if command failed
  118.   '3=all return command from &H00 to &H23 will be sent
  119.    Print #nex , "bkcmd=1";
  120.    Nexend
  121. End Sub
  122.  
  123. Dim Nex_buff(30) As Byte , Nex_idx As Byte , End_cnt As Byte , Min_len As Byte
  124. Dim New_long As Long At Nex_buff(2) Overlay
  125. Dim New_string As String * 29 At Nex_buff(2) Overlay
  126. 'for touch event
  127. Dim Touch_page As Byte At Nex_buff(2) Overlay
  128. Dim Touch_id As Byte At Nex_buff(3) Overlay
  129. Dim Touch_state As Byte At Nex_buff(4) Overlay              '1=press , 0=release
  130. 'for coordinates
  131. Dim New_x As Word At Nex_buff(2) Overlay
  132. Dim New_y As Word At Nex_buff(4) Overlay
  133.  
  134. Call Set_return_level
  135.  
  136.  
  137. Do
  138.  
  139.  
  140.  
  141.   '--[ USART0 COM1 USB ]------------------------
  142.   If 0 < Ischarwaiting(#usb) Then
  143.  
  144.    Char = Inkey(#usb)
  145.     Cmd_timeout1 = 10                                       '
  146.  
  147.    Select Case Char
  148.     Case 10 : Got_str1 = 1
  149.     Case 13
  150.     Case Else
  151.      Command1 = Command1 + Chr(char)
  152.  
  153.    End Select
  154.  
  155.    If Len(command1) > 49 Then Got_str1 = 1
  156.  
  157.    If Got_str1 = 0 Then Cmd_timeout1 = 50                   '50x10ms
  158.  
  159.    'end if Ischarwaiting
  160.   End If
  161.  
  162.   '--[ PARSE COM1 USB ]-------------------------
  163.   If Got_str1 = 1 Then
  164.  
  165.  
  166.         If 0 < Instr(command1 , "AT+RST") Then
  167.  
  168.           Print #usb , "Reseting in progress..."
  169.           'Waitms 50                                      'tylko jeśli Serialout bo wyłaczmy przerwania
  170.           Disable Interrupts
  171.           Config Watchdog = 16
  172.           Start Watchdog
  173.           Do : Loop
  174.  
  175.         Elseif 0 < Instr(command1 , "AT+ON") Then
  176.  
  177.            Print #nex , "sendxy=1";
  178.            Nexend
  179.  
  180.         Elseif 0 < Instr(command1 , "AT+OFF") Then
  181.  
  182.            Print #nex , "sendxy=0";
  183.            Nexend
  184.  
  185.         End If
  186.  
  187.       Got_str1 = 0
  188.     Command1 = ""
  189.    Cmd_timeout1 = 0
  190.  
  191.  
  192.   End If
  193.  
  194.  '--[ USART1 COM2 nex ]---------------------
  195.   If 0 < Ischarwaiting(#nex) Then
  196.  
  197.     Incr Nex_idx
  198.      Nex_buff(nex_idx) = Waitkey(#nex)
  199.      Cmd_timeout = 10                                       'unnecessary
  200.  
  201.     If Nex_idx = 1 Then                                     'check what type of msg we receiving
  202.      Select Case Nex_buff(1)
  203.  
  204.       Case 0
  205.        'it can be 4bytes Invalid_instruction
  206.        'or 6 bytes Nextion_startup (may be after reset)
  207.         Min_len = 1
  208.  
  209.       Case Touch_event
  210.         Min_len = 4
  211.       Case Touch_awake_coordinate                           '9 bytes
  212.         Min_len = 6
  213.       Case Touch_sleep_coordinate                           '9 bytes
  214.         Min_len = 6
  215.  
  216.       Case String_data                                      'it will be string with variable len
  217.         Min_len = 2
  218.       Case Numeric_data                                     'there can be FF`s so we must wait for 8 bytes
  219.         Min_len = 5
  220.  
  221.       Case Else
  222.         Min_len = 1                                         'rest of return`s have one byte followed three FF`s
  223.  
  224.      End Select
  225.  
  226.     Else
  227.                                                         'msg continue
  228.      If Nex_buff(nex_idx) = &HFF Then
  229.       If Nex_idx > Min_len Then
  230.  
  231.        If End_cnt < 2 Then
  232.         Incr End_cnt
  233.  
  234.        Else                                                 'we received third FF
  235.  
  236. '         '-----------------------------[ DEBUG ]----------
  237. '          Debug #usb , "Debug=> ";
  238. '          For N = 1 To Nex_idx
  239. '           Debug #usb , Hex(nex_buff(n)) ; " ";
  240. '          Next
  241. '          Debug #usb , ""
  242. '         '------------------------------------------------
  243.  
  244.          'parse
  245.           Select Case Nex_buff(1)
  246.  
  247.            Case Invalid_instruction
  248.  
  249.             If Nex_idx = 4 Then
  250.              Debug #usb , "Invalid instruction!"
  251.             Elseif Nex_idx = 6 Then
  252.              Debug #usb , "Nextion rebooted OK"
  253.             End If
  254.  
  255.            Case Instruction_okay
  256.              Debug #usb , "Command accepted"
  257.            Case Invalid_variable_name
  258.              Debug #usb , "Variable or component NAME not recognized!"
  259.  
  260.            Case Touch_event
  261.              If Touch_state = 0 Then
  262.               Debug #usb , "Relased object " ; Touch_id ; " on page " ; Touch_page
  263.              Else
  264.               Debug #usb , "Pressed object " ; Touch_id ; " on page " ; Touch_page
  265.              End If
  266.  
  267.            Case Touch_awake_coordinate To Touch_sleep_coordinate
  268.  
  269.               Swap New_x                                    'big endian order received
  270.               Swap New_y
  271.               Debug #usb , "Coordinates are: X=" ; New_x ; " Y=" ; New_y
  272.  
  273.            Case String_data
  274.              Helpb = Nex_idx - 2
  275.              Nex_buff(helpb) = 0                            'add string terminator
  276.              Debug #usb , "New string=> " ; New_string
  277.  
  278.  
  279.               'You can parse commands/data here
  280.  
  281.  
  282.            Case Numeric_data
  283.              Debug #usb , "New value=> " ; New_long
  284.  
  285.              'If you expect numeric data from Nextion then it will be here
  286.  
  287.           End Select
  288.  
  289.  
  290.  
  291.  
  292.           Nex_idx = 0
  293.           End_cnt = 0
  294.        End If
  295.  
  296.       End If
  297.      End If
  298.  
  299.     End If
  300.  
  301.  
  302.   End If
  303.  
  304.  
  305.  '--[ TIMER2 10ms ]----------------------------
  306.  If Tifr2.ocf2a = 1 Then
  307.   Tifr2.ocf2a = 1
  308.  
  309.   If Cmd_timeout1 > 0 Then
  310.    Decr Cmd_timeout1
  311.    If Cmd_timeout1 = 0 Then
  312.      Command1 = ""
  313.    End If
  314.   End If
  315.  
  316.   If Cmd_timeout > 0 Then
  317.    Decr Cmd_timeout
  318.    If Cmd_timeout = 0 Then
  319.     Nex_idx = 0
  320.     End_cnt = 0
  321.    End If
  322.   End If
  323.  
  324.  
  325.  
  326.   '10ms
  327.  End If
  328.  
  329.  
  330. Loop
  331. End
Awatar użytkownika
Karlos128@nos
Posty: 53
Rejestracja: 18 sie 2015, 13:32

Re: Sterowanie modułu przez UART JQ6500

Post autor: Karlos128@nos » 10 sie 2019, 22:56

Jeszcze jedno pytanko, otóż ta poniżej linijka kodu odpowiada za numer utworu, jak zrobić aby można było inkrementować tą końcówkę kodu np. z 02 na 05 , 0A,itd.
  1. Jq6500_array(5) = &H01
chodzi o =&Hxx.
Awatar użytkownika
niveasoft
Posty: 1207
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Sterowanie modułu przez UART JQ6500

Post autor: niveasoft » 10 sie 2019, 22:57

zapytaj konkretniej - dokładniej a tak w ogóle to pisze się "tę" :P
Awatar użytkownika
niveasoft
Posty: 1207
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Sterowanie modułu przez UART JQ6500

Post autor: niveasoft » 10 sie 2019, 22:59

bascom pozwala na N+4 w nawiasach - musisz uscislić pytanie
Awatar użytkownika
niveasoft
Posty: 1207
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Sterowanie modułu przez UART JQ6500

Post autor: niveasoft » 10 sie 2019, 23:04

  1. Jq6500_array(5) = N
Nic nie bój - to moze byc zmienna
Awatar użytkownika
Karlos128@nos
Posty: 53
Rejestracja: 18 sie 2015, 13:32

Re: Sterowanie modułu przez UART JQ6500

Post autor: Karlos128@nos » 10 sie 2019, 23:16

  1. dim mowa as byte
  2. Jq6500_array(5) = tutaj będzie odtwarzany 1 z 50 komunikatów głosowych.
w jaki sposób można zmieniać tą wartość &H01 aż do &HFF.
chodzi mi o zwiększanie lub zmniejszanie w postaci hexa i przepisane jej pod mowa.
ODPOWIEDZ