Strona 1 z 1

ESP8266 i Atmega 8Mhz

: 31 sty 2018, 2:50
autor: kulamario
Witam
Mam mały problem dostałem kod od Bartka do czytania czasu z serwera UTC i o ile kod na atmedze taktowanej 16Mhz działa to za chiny nie mogę tego odpalić na 8Mhz
To jest kod na 16Mhz
  1. $regfile = "m32def.dat"
  2. $crystal = 16000000                                         '11059200
  3. $swstack = 64
  4. $hwstack = 64
  5. $framesize = 200
  6. $baud = 115200                                              '115200
  7.  
  8. Config Submode = New
  9.  
  10. '****************************************************************
  11. '*               PROGRAMM CONSTANTS/SETTINGS                    *
  12. '****************************************************************
  13.  Const Nastepny_odczyt_ntp = 3600                           'synchronizacja czasu co godzinê
  14.  
  15. '****************************************************************
  16. '*                ALPHANUMERIC LCD CONFIG                       *
  17. '****************************************************************
  18.  
  19.  
  20. Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0       'ZL3AVR
  21. Config Lcd = 20x4
  22.  
  23. 'Config Lcd = 16 * 2
  24. 'Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2       'ZL2AVR
  25.  
  26. Deflcdchar 1 , 2 , 15 , 20 , 16 , 14 , 1 , 1 , 30           ' replace [x] with number (0-7)
  27.  
  28. Cursor Off Noblink
  29.  
  30. Cls
  31.  
  32.  
  33. '****************************************************************
  34. '*         CONFIG FOR HARDWARE TWI (I2C)                        *
  35. '****************************************************************
  36.    $lib "i2c_twi.lbx"
  37.  
  38.    Config Scl = Portc.0
  39.    Config Sda = Portc.1
  40.    I2cinit
  41.    Config Twi = 400000
  42.  
  43. '*****************************************************************
  44. '*            CONFIG FOR DS3231 I2C CLOCK (RTC)                  *
  45. '*****************************************************************
  46.  Config Clock = User
  47.   Config Date = Dmy , Separator = /
  48.   'address of ds1307
  49.     Const Ds3231w = &HD0
  50.     Const Ds3231r = &HD1
  51.  Dim Weekday As Byte , Old_day As Byte , Weekday_str As String * 10
  52.  
  53. '*****************************************************************
  54. '*               USART CONFIG FOR ESP8266                        *
  55. '*****************************************************************
  56. Config Serialin0 = Buffered , Size = 100                    ' from ESP8266
  57. Config Serialout0 = Buffered , Size = 100                   ' to ESP8266
  58.  Open "COM1:" For Binary As #1
  59. Echo Off : $timeout = 3000
  60.  
  61. '*****************************************************************
  62. '*                 SOFTWARE PORT FOR DEBUG                       *
  63. '*****************************************************************
  64.  
  65.      Open "COMC.7:115200,8,n,1" For Output As #2
  66.  
  67. '*****************************************************************
  68. '*                 I/O PIN`s CONFIGURATION                       *
  69. '*****************************************************************
  70.  
  71.  'Config Portb.0 = Output : Set Portb.0 : Buzz Alias Portb.0
  72.  
  73. '*****************************************************************
  74. '*               TIMER2 CONFIG FOR TIME BASE                     *
  75. '*****************************************************************
  76.  
  77. Config Timer2 = Timer , Prescale = 1024 , Compare = Disconnect , Pwm = Off , Clear Timer = 1
  78. On Compare2 Timer2_isr Nosave : Compare2 = 215              '20ms @11MHz/1024Hz
  79.  
  80. Dim 20ms As Byte , 100ms As Byte
  81.  
  82. '*****************************************************************
  83. '*           TIMER0 CONFIG FOR LCD BACKLIGHT PWM                 *
  84. '*****************************************************************
  85. 'Config Timer0 = Pwm , Prescale = 1 , Pwm = On , Compare Pwm = Clear Up
  86.  ' Pwm0 = 50
  87.  
  88. '*****************************************************************
  89. '*                        VARIABLES                              *
  90. '*****************************************************************
  91. Dim Second_tick As Byte , Timeout As Byte , Sys_sec As Long , No_ntp As Byte , Ntp_progress As Byte
  92. Dim Wait_start As Byte , Got_time As Byte , Net_status As Byte , Wait_answear As Byte
  93. Dim Got_match As Byte , Inp_str1 As String * 100 , Char As Byte , Idx As Byte , Helpb As Byte
  94. Dim Answear As Byte , Insp As Byte
  95.  Okay Alias 1
  96. Error Alias 2
  97.  
  98. ' Ntp Stuff
  99. Dim Timestr As String * 10
  100. Dim Tt(4) As String * 1
  101. Dim Ss(4) As Byte
  102. Dim L1 As Long At Ss Overlay                                ' Overlay a long variable to receive-string
  103. Dim L2 As Long                                              ' with overlay you need no transfer from the byte-array to a long-variable
  104. Dim Odczekaj_czas As Word
  105. Dim Info_timeout As Byte
  106. Const Letni = "AT+GMT=2"
  107. Const Zimowy = "AT+GMT=1"
  108. Dim Daylight_saving As String * 10
  109.  
  110. '***** wpisuje do DS-a "pierdo³y" ¿eby widziæ pierwsze synchro *****
  111.  Time$ = "00:00:00"                                         'automatycznie zapisze w DS`ie
  112.  Date$ = "00-01-01"                                         'automatycznie zapisze w DS`ie
  113. '*****--------------------------------------------------------*****
  114.  
  115. Sub Ntp_dst_correction
  116.    'Dont change order of time and date variables !!! This order is required for Date/Time functions used.
  117.    'this routine is orginated by framuel
  118.    Local Second As Byte
  119.    Local Minute As Byte
  120.    Local Hour As Byte
  121.    Local Day As Byte
  122.    Local Month As Byte
  123.    Local Year As Byte
  124.    Local Dow As Byte                                        'Day of week
  125.  
  126.       Day = Date(l2)                                        'set 3 variables: Day, Month, Year, so Year contains now current year
  127.  
  128.    'DST starts at the last sunday of March, so let's see what weekday the 1st of April is
  129.       Month = 4
  130.       Day = 1
  131.       Hour = 2
  132.       Minute = 0
  133.       Second = 0
  134.       Dow = Dayofweek(day)                                  '0 = Monday to 6 = Sunday
  135.       Day = 31 - Dow                                        'Now count back the days until last sunday
  136.  
  137.       Month = 3                                             'and set month to March
  138.  
  139.       If L2 >= Syssec(second) Then
  140.  
  141.         'DST ends at the last sunday of October, so let's see what weekday the 1st of November is
  142.           Day = 1
  143.           Month = 11
  144.           Dow = Dayofweek(day)                              '0 = Monday to 6 = Sunday
  145.           Day = 31 - Dow                                    'Now count back the days until last sunday
  146.           Month = 10                                        'and set month to October
  147.  
  148.           Locate 3 , 1
  149.           If L2 < Syssec(second) Then                       'jeœli data w sysec mniejsza od aktulnej to jest lato
  150.             L2 = L2 + 3600                                  '7200
  151.              Lcd "Sumer Time"
  152.           Else
  153.             L2 = L2 + 0                                     '3600
  154.              Lcd "Winter Time"
  155.           End If
  156.  
  157.       End If
  158.  
  159. End Sub
  160.  
  161. Enable Compare2
  162. Enable Interrupts
  163.  
  164. Print #1 , "AT+RST"
  165.  Print#2 , "Started.."
  166.  
  167. Do
  168.  
  169.   If 20ms = 1 Then
  170.    20ms = 0
  171.     Incr 100ms
  172.      'Set Buzz
  173.   End If
  174.  
  175.  
  176.   If Ischarwaiting(#1) > 0 Then
  177.  
  178.    Char = Inkey(#1)
  179.  
  180.    Select Case Char
  181.      Case 10
  182.      Case 13 : Got_match = 1
  183.      Case Else
  184.       Inp_str1 = Inp_str1 + Chr(char)
  185.        Incr Idx
  186.         If Idx > 99 Then Got_match = 1
  187.  
  188.    End Select
  189.  
  190.   End If
  191.  
  192.   If Got_match = 1 Then
  193.    Got_match = 0
  194.  
  195.     If Inp_str1 <> "" Then
  196.  
  197.      Select Case Inp_str1
  198.  
  199.       Case "SEND OK"
  200.         Answear = Okay
  201.  
  202.       Case "OK"
  203.         Answear = Okay
  204.  
  205.       Case "ERROR"
  206.         Answear = Error
  207.  
  208.       Case "WIFI GOT IP"
  209.         Net_status = 1
  210.  
  211.       Case "WIFI CONNECTED"
  212.  
  213.       Case "WIFI DISCONNECT"
  214.         Net_status = 0
  215.  
  216.       Case Else
  217.  
  218.        Insp = Instr(inp_str1 , ",CONNECT")
  219.         If Insp > 0 Then Answear = Okay
  220.  
  221.        Insp = Instr(inp_str1 , "+IPD,1,4:")
  222.         If Insp > 0 Then
  223.  
  224.          Timestr = Mid(inp_str1 , 10 , 4)
  225.  
  226.          Tt(1) = Mid(timestr , 4 , 1)                       'from big endian to little endian
  227.          Tt(2) = Mid(timestr , 3 , 1)                       'swap the bytes
  228.          Tt(3) = Mid(timestr , 2 , 1)
  229.          Tt(4) = Mid(timestr , 1 , 1)
  230.          Ss(1) = Asc(tt(1))                                 'this is  L1 split in 4s by overlay
  231.          Ss(2) = Asc(tt(2))
  232.          Ss(3) = Asc(tt(3))
  233.          Ss(4) = Asc(tt(4))
  234.          L2 = L1 + 1139293696
  235.          'L2 = L2 + 7200                                     ' offset in seconds UTC + 2 hour
  236.  
  237.          Call Ntp_dst_correction
  238.  
  239.          Time$ = Time(l2)                                   'set the time
  240.          Date$ = Date(l2)                                   'set the date
  241.           Sys_sec = Syssec(time$ , Date$)
  242.            Got_time = 1
  243.             Odczekaj_czas = Nastepny_odczyt_ntp
  244.              'Reset Buzz
  245.  
  246.           Locate 4 , 1 : Lcd Spc(16)                        'clear Lowerline
  247.           Locate 4 , 4 : Lcd "Download Time" : Info_timeout = 2
  248.         End If
  249.  
  250.      End Select
  251.  
  252.     End If
  253.  
  254.     'Locate 1 , 16 : Lcd "*"
  255.  
  256.     Print #2 , Inp_str1
  257.  
  258.     Inp_str1 = ""
  259.      Idx = 0
  260.  
  261.   End If
  262.  
  263.   If 100ms > 9 Then                                         '200ms
  264.    100ms = 0
  265.     Incr Second_tick
  266.  
  267.  
  268.       If Net_status = 1 Then
  269.         If No_ntp = 1 Then
  270.  
  271.           Select Case Ntp_progress
  272.  
  273.            Case 1
  274.  
  275.               Print #1 , "AT+CIPMUX=1"
  276.                Incr Ntp_progress
  277.  
  278.            Case 2
  279.  
  280.             Select Case Answear
  281.              Case Okay
  282.              Waitms 200
  283.               Print #1 , "AT+CIPSTART=1," ; Chr(34) ; "UDP" ; Chr(34) ; "," ; Chr(34) ; "193.67.79.202" ; Chr(34) ; ",37"
  284.  
  285.               '                              MIREK 132.163.4.103 /DE 193.67.79.202 /TPSA 217.96.29.26 /193.67.79.202  ,217.96.29.26
  286.                Incr Ntp_progress
  287.              Case Error
  288.             End Select
  289.  
  290.            Case 3
  291.  
  292.             Select Case Answear
  293.              Case Okay
  294.               Print #1 , "AT+CIPSEND=1,3"
  295.                Incr Ntp_progress
  296.              Case Error
  297.             End Select
  298.  
  299.            Case 4
  300.  
  301.             Select Case Answear
  302.              Case Okay
  303.               Print #1 , "X"
  304.                Incr Ntp_progress
  305.                 Wait_answear = 5
  306.              Case Error
  307.             End Select
  308.  
  309.            Case 5
  310.  
  311.             If Answear > 0 Then
  312.               Incr Ntp_progress
  313.             End If
  314.  
  315.            Case 6
  316.  
  317.            If Wait_answear > 0 Then
  318.             Decr Wait_answear
  319.             If Got_time = 1 Then
  320.              No_ntp = 0
  321.               Print #1 , "AT+CIPCLOSE=1"
  322.                Incr Ntp_progress
  323.             End If
  324.            Else
  325.             Print #1 , "AT+CIPCLOSE=1"
  326.                Incr Ntp_progress
  327.            End If
  328.  
  329.           End Select
  330.  
  331.         End If
  332.       End If
  333.  
  334.       Answear = 0
  335.  
  336.   End If
  337.  
  338.   If Second_tick > 4 Then                                   '5x200ms=1s
  339.    Second_tick = 0
  340.  
  341.     'Locate 1 , 16 : Lcd " "
  342.  
  343. '   Incr Sys_sec
  344. '    Time$ = Time(sys_sec)
  345.  
  346.     Locate 1 , 7 : Lcd Time$
  347.     Locate 2 , 7 : Lcd Date$
  348.     If Info_timeout > 0 Then
  349.      Decr Info_timeout
  350.       If Info_timeout = 0 Then Old_day = 0
  351.     End If
  352.  
  353.     If Old_day <> _day Then
  354.      Old_day = _day
  355.        Weekday = Dayofweek()
  356.         Weekday_str = Lookupstr(weekday , Weekdays)
  357.          Helpb = 12 - Len(weekday_str)
  358.           If Helpb > 0 Then Weekday_str = Space(helpb) + Weekday_str
  359.            Locate 4 , 1 : Lcd Spc(16)                       'clear Lowerline
  360.            Locate 3 , 2 : Lcd Weekday_str
  361.     End If
  362.  
  363.      If Odczekaj_czas > 0 Then Decr Odczekaj_czas
  364.      If Odczekaj_czas = 0 Then
  365.       No_ntp = 1
  366.        Ntp_progress = 1
  367.         Odczekaj_czas = 20
  368.          ' Locate 2 , 1 : Lcd Spc(16)                        'clear Lowerline
  369.           Locate 4 , 6 : Lcd "Loading..."                   ': Info_timeout = 2
  370.  
  371.      End If
  372.  
  373.   End If
  374.  
  375. Loop
  376. End
  377.  
  378. Timer2_isr:
  379.  
  380.  $asm
  381.   !PUSH R24
  382.   !in R24, sreg
  383.   !PUSH  R24
  384.   $end Asm
  385.  
  386.   20ms = 1
  387.     '          Tuned with NoSave Tool
  388.  
  389.   $asm
  390.   !POP  R24
  391.   !out sreg, r24
  392.   !POP R24
  393.   $end Asm
  394.  
  395. Return
  396.  
  397.  
  398. Getdatetime:
  399. I2cstart                                                    ' Generate start code
  400.  I2cwbyte Ds3231w                                           ' send address
  401.  I2cwbyte 0                                                 ' start address in 1307
  402.  
  403. I2cstart                                                    ' Generate start code
  404.  I2cwbyte Ds3231r                                           ' send address
  405.  I2crbyte _sec , Ack
  406.  I2crbyte _min , Ack                                        ' MINUTES
  407.  I2crbyte _hour , Ack                                       ' Hours
  408.  I2crbyte Weekday , Ack                                     ' Day of Week
  409.  I2crbyte _day , Ack                                        ' Day of Month
  410.  I2crbyte _month , Ack                                      ' Month of Year
  411.  I2crbyte _year , Nack                                      ' Year
  412. I2cstop
  413.  _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
  414.  _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
  415. Return
  416.  
  417. Setdate:
  418.  _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
  419. I2cstart                                                    ' Generate start code
  420.  I2cwbyte Ds3231w                                           ' send address
  421.  I2cwbyte 4                                                 ' starting address in 1307
  422.  I2cwbyte _day                                              ' Send Data to SECONDS
  423.  I2cwbyte _month                                            ' MINUTES
  424.  I2cwbyte _year                                             ' Hours
  425. I2cstop
  426. Return
  427.  
  428. Settime:
  429.  _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
  430. I2cstart                                                    ' Generate start code
  431.  I2cwbyte Ds3231w                                           ' send address
  432.  I2cwbyte 0                                                 ' starting address in 1307
  433.  I2cwbyte _sec                                              ' Send Data to SECONDS
  434.  I2cwbyte _min                                              ' MINUTES
  435.  I2cwbyte _hour                                             ' Hours
  436. I2cstop
  437. Return
  438.  
  439. Weekdays:
  440. Data "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday"
  441. 'Data "Poniedzialek" , "Wtorek" , "{001}roda" , "Czwartek" , "Piatek" , "Sobota" , "Niedziela"
a to jest kod po przeróbce na 8Mhz
  1. $regfile = "m32def.dat"
  2. $crystal = 8000000                                          '11059200
  3. $swstack = 64
  4. $hwstack = 64
  5. $framesize = 200
  6. $baud = 9600                                                '115200
  7.  
  8. Config Submode = New
  9.  
  10. '****************************************************************
  11. '*               PROGRAMM CONSTANTS/SETTINGS                    *
  12. '****************************************************************
  13.  Const Nastepny_odczyt_ntp = 3600                           'synchronizacja czasu co godzinê
  14.  
  15. '****************************************************************
  16. '*                ALPHANUMERIC LCD CONFIG                       *
  17. '****************************************************************
  18.  
  19.  
  20. Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0       'ZL3AVR
  21. Config Lcd = 20x4
  22.  
  23. 'Config Lcd = 16 * 2
  24. 'Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2       'ZL2AVR
  25.  
  26. Deflcdchar 1 , 2 , 15 , 20 , 16 , 14 , 1 , 1 , 30           ' replace [x] with number (0-7)
  27.  
  28. Cursor Off Noblink
  29.  
  30. Cls
  31.  
  32.  
  33. '****************************************************************
  34. '*         CONFIG FOR HARDWARE TWI (I2C)                        *
  35. '****************************************************************
  36.    $lib "i2c_twi.lbx"
  37.  
  38.    Config Scl = Portc.0
  39.    Config Sda = Portc.1
  40.    I2cinit
  41.    Config Twi = 400000
  42.  
  43. '*****************************************************************
  44. '*            CONFIG FOR DS3231 I2C CLOCK (RTC)                  *
  45. '*****************************************************************
  46.  Config Clock = User
  47.   Config Date = Dmy , Separator = /
  48.   'address of ds1307
  49.     Const Ds3231w = &HD0
  50.     Const Ds3231r = &HD1
  51.  Dim Weekday As Byte , Old_day As Byte , Weekday_str As String * 10
  52.  
  53. '*****************************************************************
  54. '*               USART CONFIG FOR ESP8266                        *
  55. '*****************************************************************
  56. Config Serialin0 = Buffered , Size = 100                    ' from ESP8266
  57. Config Serialout0 = Buffered , Size = 100                   ' to ESP8266
  58.  Open "COM1:" For Binary As #1
  59. Echo Off : $timeout = 3000
  60.  
  61. '*****************************************************************
  62. '*                 SOFTWARE PORT FOR DEBUG                       *
  63. '*****************************************************************
  64.  
  65.      Open "COMC.7:9600,8,n,1" For Output As #2
  66.  
  67. '*****************************************************************
  68. '*                 I/O PIN`s CONFIGURATION                       *
  69. '*****************************************************************
  70.  
  71.  'Config Portb.0 = Output : Set Portb.0 : Buzz Alias Portb.0
  72.  
  73. '*****************************************************************
  74. '*               TIMER2 CONFIG FOR TIME BASE                     *
  75. '*****************************************************************
  76.  
  77. Config Timer2 = Timer , Prescale = 1024 , Compare = Disconnect , Pwm = Off , Clear Timer = 1
  78. On Compare2 Timer2_isr Nosave : Compare2 = 77               '20ms @11MHz/1024Hz
  79.  
  80. Dim 20ms As Byte , 100ms As Byte
  81.  
  82. '*****************************************************************
  83. '*           TIMER0 CONFIG FOR LCD BACKLIGHT PWM                 *
  84. '*****************************************************************
  85. 'Config Timer0 = Pwm , Prescale = 1 , Pwm = On , Compare Pwm = Clear Up
  86.  ' Pwm0 = 50
  87.  
  88. '*****************************************************************
  89. '*                        VARIABLES                              *
  90. '*****************************************************************
  91. Dim Second_tick As Byte , Timeout As Byte , Sys_sec As Long , No_ntp As Byte , Ntp_progress As Byte
  92. Dim Wait_start As Byte , Got_time As Byte , Net_status As Byte , Wait_answear As Byte
  93. Dim Got_match As Byte , Inp_str1 As String * 100 , Char As Byte , Idx As Byte , Helpb As Byte
  94. Dim Answear As Byte , Insp As Byte
  95.  Okay Alias 1
  96. Error Alias 2
  97.  
  98. ' Ntp Stuff
  99. Dim Timestr As String * 10
  100. Dim Tt(4) As String * 1
  101. Dim Ss(4) As Byte
  102. Dim L1 As Long At Ss Overlay                                ' Overlay a long variable to receive-string
  103. Dim L2 As Long                                              ' with overlay you need no transfer from the byte-array to a long-variable
  104. Dim Odczekaj_czas As Word
  105. Dim Info_timeout As Byte
  106. Const Letni = "AT+GMT=2"
  107. Const Zimowy = "AT+GMT=1"
  108. Dim Daylight_saving As String * 10
  109.  
  110. '***** wpisuje do DS-a "pierdo³y" ¿eby widziæ pierwsze synchro *****
  111.  Time$ = "00:00:00"                                         'automatycznie zapisze w DS`ie
  112.  Date$ = "00-01-01"                                         'automatycznie zapisze w DS`ie
  113. '*****--------------------------------------------------------*****
  114.  
  115. Sub Ntp_dst_correction
  116.    'Dont change order of time and date variables !!! This order is required for Date/Time functions used.
  117.    'this routine is orginated by framuel
  118.    Local Second As Byte
  119.    Local Minute As Byte
  120.    Local Hour As Byte
  121.    Local Day As Byte
  122.    Local Month As Byte
  123.    Local Year As Byte
  124.    Local Dow As Byte                                        'Day of week
  125.  
  126.       Day = Date(l2)                                        'set 3 variables: Day, Month, Year, so Year contains now current year
  127.  
  128.    'DST starts at the last sunday of March, so let's see what weekday the 1st of April is
  129.       Month = 4
  130.       Day = 1
  131.       Hour = 2
  132.       Minute = 0
  133.       Second = 0
  134.       Dow = Dayofweek(day)                                  '0 = Monday to 6 = Sunday
  135.       Day = 31 - Dow                                        'Now count back the days until last sunday
  136.  
  137.       Month = 3                                             'and set month to March
  138.  
  139.       If L2 >= Syssec(second) Then
  140.  
  141.         'DST ends at the last sunday of October, so let's see what weekday the 1st of November is
  142.           Day = 1
  143.           Month = 11
  144.           Dow = Dayofweek(day)                              '0 = Monday to 6 = Sunday
  145.           Day = 31 - Dow                                    'Now count back the days until last sunday
  146.           Month = 10                                        'and set month to October
  147.  
  148.           Locate 3 , 1
  149.           If L2 < Syssec(second) Then                       'jeœli data w sysec mniejsza od aktulnej to jest lato
  150.             L2 = L2 + 3600                                  '7200
  151.              Lcd "Sumer Time"
  152.           Else
  153.             L2 = L2 + 0                                     '3600
  154.              Lcd "Winter Time"
  155.           End If
  156.  
  157.       End If
  158.  
  159. End Sub
  160.  
  161. Enable Compare2
  162. Enable Interrupts
  163.  
  164. Print #1 , "AT+RST"
  165.  Print#2 , "Started.."
  166.  
  167. Do
  168.  
  169.   If 20ms = 1 Then
  170.    20ms = 0
  171.     Incr 100ms
  172.      'Set Buzz
  173.   End If
  174.  
  175.  
  176.   If Ischarwaiting(#1) > 0 Then
  177.  
  178.    Char = Inkey(#1)
  179.  
  180.    Select Case Char
  181.      Case 10
  182.      Case 13 : Got_match = 1
  183.      Case Else
  184.       Inp_str1 = Inp_str1 + Chr(char)
  185.        Incr Idx
  186.         If Idx > 99 Then Got_match = 1
  187.  
  188.    End Select
  189.  
  190.   End If
  191.  
  192.   If Got_match = 1 Then
  193.    Got_match = 0
  194.  
  195.     If Inp_str1 <> "" Then
  196.  
  197.      Select Case Inp_str1
  198.  
  199.       Case "SEND OK"
  200.         Answear = Okay
  201.  
  202.       Case "OK"
  203.         Answear = Okay
  204.  
  205.       Case "ERROR"
  206.         Answear = Error
  207.  
  208.       Case "WIFI GOT IP"
  209.         Net_status = 1
  210.  
  211.       Case "WIFI CONNECTED"
  212.  
  213.       Case "WIFI DISCONNECT"
  214.         Net_status = 0
  215.  
  216.       Case Else
  217.  
  218.        Insp = Instr(inp_str1 , ",CONNECT")
  219.         If Insp > 0 Then Answear = Okay
  220.  
  221.        Insp = Instr(inp_str1 , "+IPD,1,4:")
  222.         If Insp > 0 Then
  223.  
  224.          Timestr = Mid(inp_str1 , 10 , 4)
  225.  
  226.          Tt(1) = Mid(timestr , 4 , 1)                       'from big endian to little endian
  227.          Tt(2) = Mid(timestr , 3 , 1)                       'swap the bytes
  228.          Tt(3) = Mid(timestr , 2 , 1)
  229.          Tt(4) = Mid(timestr , 1 , 1)
  230.          Ss(1) = Asc(tt(1))                                 'this is  L1 split in 4s by overlay
  231.          Ss(2) = Asc(tt(2))
  232.          Ss(3) = Asc(tt(3))
  233.          Ss(4) = Asc(tt(4))
  234.          L2 = L1 + 1139293696
  235.          'L2 = L2 + 7200                                     ' offset in seconds UTC + 2 hour
  236.  
  237.          Call Ntp_dst_correction
  238.  
  239.          Time$ = Time(l2)                                   'set the time
  240.          Date$ = Date(l2)                                   'set the date
  241.           Sys_sec = Syssec(time$ , Date$)
  242.            Got_time = 1
  243.             Odczekaj_czas = Nastepny_odczyt_ntp
  244.              'Reset Buzz
  245.  
  246.           Locate 4 , 1 : Lcd Spc(16)                        'clear Lowerline
  247.           Locate 4 , 4 : Lcd "Download Time" : Info_timeout = 2
  248.         End If
  249.  
  250.      End Select
  251.  
  252.     End If
  253.  
  254.     'Locate 1 , 16 : Lcd "*"
  255.  
  256.     Print #2 , Inp_str1
  257.  
  258.     Inp_str1 = ""
  259.      Idx = 0
  260.  
  261.   End If
  262.  
  263.   If 100ms > 9 Then                                         '200ms
  264.    100ms = 0
  265.     Incr Second_tick
  266.  
  267.  
  268.       If Net_status = 1 Then
  269.         If No_ntp = 1 Then
  270.  
  271.           Select Case Ntp_progress
  272.  
  273.            Case 1
  274.  
  275.               Print #1 , "AT+CIPMUX=1"
  276.                Incr Ntp_progress
  277.  
  278.            Case 2
  279.  
  280.             Select Case Answear
  281.              Case Okay
  282.              Waitms 200
  283.               Print #1 , "AT+CIPSTART=1," ; Chr(34) ; "UDP" ; Chr(34) ; "," ; Chr(34) ; "193.67.79.202" ; Chr(34) ; ",37"
  284.  
  285.               '                              MIREK 132.163.4.103 /DE 193.67.79.202 /TPSA 217.96.29.26 /193.67.79.202  ,217.96.29.26
  286.                Incr Ntp_progress
  287.              Case Error
  288.             End Select
  289.  
  290.            Case 3
  291.  
  292.             Select Case Answear
  293.              Case Okay
  294.               Print #1 , "AT+CIPSEND=1,3"
  295.                Incr Ntp_progress
  296.              Case Error
  297.             End Select
  298.  
  299.            Case 4
  300.  
  301.             Select Case Answear
  302.              Case Okay
  303.               Print #1 , "X"
  304.                Incr Ntp_progress
  305.                 Wait_answear = 5
  306.              Case Error
  307.             End Select
  308.  
  309.            Case 5
  310.  
  311.             If Answear > 0 Then
  312.               Incr Ntp_progress
  313.             End If
  314.  
  315.            Case 6
  316.  
  317.            If Wait_answear > 0 Then
  318.             Decr Wait_answear
  319.             If Got_time = 1 Then
  320.              No_ntp = 0
  321.               Print #1 , "AT+CIPCLOSE=1"
  322.                Incr Ntp_progress
  323.             End If
  324.            Else
  325.             Print #1 , "AT+CIPCLOSE=1"
  326.                Incr Ntp_progress
  327.            End If
  328.  
  329.           End Select
  330.  
  331.         End If
  332.       End If
  333.  
  334.       Answear = 0
  335.  
  336.   End If
  337.  
  338.   If Second_tick > 4 Then                                   '5x200ms=1s
  339.    Second_tick = 0
  340.  
  341.     'Locate 1 , 16 : Lcd " "
  342.  
  343. '   Incr Sys_sec
  344. '    Time$ = Time(sys_sec)
  345.  
  346.     Locate 1 , 7 : Lcd Time$
  347.     Locate 2 , 7 : Lcd Date$
  348.     If Info_timeout > 0 Then
  349.      Decr Info_timeout
  350.       If Info_timeout = 0 Then Old_day = 0
  351.     End If
  352.  
  353.     If Old_day <> _day Then
  354.      Old_day = _day
  355.        Weekday = Dayofweek()
  356.         Weekday_str = Lookupstr(weekday , Weekdays)
  357.          Helpb = 12 - Len(weekday_str)
  358.           If Helpb > 0 Then Weekday_str = Space(helpb) + Weekday_str
  359.            Locate 4 , 1 : Lcd Spc(16)                       'clear Lowerline
  360.            Locate 3 , 2 : Lcd Weekday_str
  361.     End If
  362.  
  363.      If Odczekaj_czas > 0 Then Decr Odczekaj_czas
  364.      If Odczekaj_czas = 0 Then
  365.       No_ntp = 1
  366.        Ntp_progress = 1
  367.         Odczekaj_czas = 20
  368.          ' Locate 2 , 1 : Lcd Spc(16)                        'clear Lowerline
  369.           Locate 4 , 6 : Lcd "Loading..."                   ': Info_timeout = 2
  370.  
  371.      End If
  372.  
  373.   End If
  374.  
  375. Loop
  376. End
  377.  
  378. Timer2_isr:
  379.  
  380.  $asm
  381.   !PUSH R24
  382.   !in R24, sreg
  383.   !PUSH  R24
  384.   $end Asm
  385.  
  386.   20ms = 1
  387.     '          Tuned with NoSave Tool
  388.  
  389.   $asm
  390.   !POP  R24
  391.   !out sreg, r24
  392.   !POP R24
  393.   $end Asm
  394.  
  395. Return
  396.  
  397.  
  398. Getdatetime:
  399. I2cstart                                                    ' Generate start code
  400.  I2cwbyte Ds3231w                                           ' send address
  401.  I2cwbyte 0                                                 ' start address in 1307
  402.  
  403. I2cstart                                                    ' Generate start code
  404.  I2cwbyte Ds3231r                                           ' send address
  405.  I2crbyte _sec , Ack
  406.  I2crbyte _min , Ack                                        ' MINUTES
  407.  I2crbyte _hour , Ack                                       ' Hours
  408.  I2crbyte Weekday , Ack                                     ' Day of Week
  409.  I2crbyte _day , Ack                                        ' Day of Month
  410.  I2crbyte _month , Ack                                      ' Month of Year
  411.  I2crbyte _year , Nack                                      ' Year
  412. I2cstop
  413.  _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
  414.  _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
  415. Return
  416.  
  417. Setdate:
  418.  _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
  419. I2cstart                                                    ' Generate start code
  420.  I2cwbyte Ds3231w                                           ' send address
  421.  I2cwbyte 4                                                 ' starting address in 1307
  422.  I2cwbyte _day                                              ' Send Data to SECONDS
  423.  I2cwbyte _month                                            ' MINUTES
  424.  I2cwbyte _year                                             ' Hours
  425. I2cstop
  426. Return
  427.  
  428. Settime:
  429.  _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
  430. I2cstart                                                    ' Generate start code
  431.  I2cwbyte Ds3231w                                           ' send address
  432.  I2cwbyte 0                                                 ' starting address in 1307
  433.  I2cwbyte _sec                                              ' Send Data to SECONDS
  434.  I2cwbyte _min                                              ' MINUTES
  435.  I2cwbyte _hour                                             ' Hours
  436. I2cstop
  437. Return
  438.  
  439. Weekdays:
  440. Data "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday"
  441. 'Data "Poniedzialek" , "Wtorek" , "{001}roda" , "Czwartek" , "Piatek" , "Sobota" , "Niedziela"
Zmienilem ustawienia w programie z 115200 na 9600 zmienilem tez ustawienia Timer2 wydaje mi sie ze dobrze to wszystko poustawialem ale cos jest nie tak
Gdzie jest blad ?
Co robie nie tak ?
ESP8266 mam ustawiony na 9600 a nie na 115200 wiec powinno chyba ruszyc a nie chce

Re: ESP8266 i Atmega 8Mhz

: 31 sty 2018, 3:16
autor: niveasoft
Gdzie tam masz zmienione te ustawienia dla Timer2 jak 20ms @8MHz /1024 to powinno dać COMPARE2 = 155
Po drugie przy 8MHz tak jak nie da się się zrobić UART na 115200 tak chyba TWI/I2C nie pójdzie na 400_000 i zmieniłbym na 100_000

Na pewno zmieniłeś prędkość dla ESP? W nowszych softach pisze się AT+UART_DEF=9600,8,1,0,0

Re: ESP8266 i Atmega 8Mhz

: 31 sty 2018, 7:50
autor: kulamario
Niveasoft powiem tak
Błąd był ale nie w sofcie a w sposobie ustawienia szybkości w ESP8266
Ja ustawiałem w ten sposób AT+IPR=9600 a tak niestety ale firmware się sypał
Bartek dal przykład taki
AT+UART_DEF=9600,8,1,0,0
i to ruszyło od kopa układ na 8Mhz
Nawet Twi może zostać na 400000 i Compare2 = 77 a czas i tak jest sczytany z neta

Re: ESP8266 i Atmega 8Mhz

: 31 sty 2018, 9:06
autor: niveasoft
Bo widzisz to się wszystko łączy.
Pisałem o SumatraPDF.
Mam Sumatrę to lubię czytać...

I tu najpierw na stronie 11 czytasz że AT+UART jest @depreciated i później na stronie 16 masz właściwą komendę z przykładem.
AT+IPR było depreciated już w poprzednich wersjach ;)