Write RTC time by UART port ...

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
Darklakebridge78
Posts: 136
Joined: 12 May 2007 14:04
Location: Italy
Contact:

Write RTC time by UART port ...

#1 Post by Darklakebridge78 » 30 Mar 2021 21:33

Hello everyone! For some days I have been trying to create a firmware to program the RTC (DS1337) connected to a PIC32MX460F512L, through the serial and VbNet. To do this, I send the letter H followed by the time, for example: 2227 (h22 m27). I have tried to write this firmware which seems to work. But only once, because then the serial is blocked and it is no longer possible to write anything else. Where am I doing wrong? Has anyone ever done anything like this?

Code: Select all

     if (UART1_Data_Ready() <> 0) then
        UartDataReceived = UART1_read
            if UartDataReceived = 72 then                                          'IF THE CONTROL SOFTWARE SENDS "H" -> "HOURS" ON THE SERIAL ...

            for I = 0 to 3
               output[I] = UART1_read
            next I

            SetHr = ((Output[0] - 48) * 10) + Output[1]
            SetMin = ((Output[2] - 48) * 10) + Output[3]

            SetHr = dec2bcd(SetHr)
            SetMin = dec2bcd(SetMin)

            I2C2_Start()          ' issue start signal
            I2C2_Write(0xD0)      ' address DS1307
            I2C2_Write(0)         ' start from word at address
            I2C2_Write(0x00)      ' write 00 to seconds word
            I2C2_Write(SetMin)    'write minutes 
            I2C2_Write(SetHr)      ' write  hours 
            I2C2_Write(0x03)      ' write 7 - >Sat
            I2C2_Write(0x30)      ' write 4 to date word
            I2C2_Write(0x03)      ' write 11 (nov) to month word
            I2C2_Write(0x21)      ' write 17 to year word
            I2C2_Write(0x00)      ' alm1 seconds
            I2C2_Write(0x00)      ' alm1 minutes
            I2C2_Write(0x00)      ' alm1 hours
            I2C2_Write(0x00)      ' alm1 day/date
            I2C2_Write(0x00)      ' alm2 minutes
            I2C2_Write(0x00)      ' alm2 hours
            I2C2_Write(0x00)      ' alm2 day/date
            I2C2_Write(0x04)      ' turn off the squarewave output pin
            I2C2_Write(0x00)      ' clear the status registers
            I2C2_Stop()           ' issue stop signal

            VisualTftTime()

         end if
        end if

MikroC PRO for PIC, MikroC PRO for dsPIC, MikroC PRO for PIC32, MikroC PRO for ARM, Visual TFT, Visual GLCD,
http://www.teolab.it

Darklakebridge78
Posts: 136
Joined: 12 May 2007 14:04
Location: Italy
Contact:

Re: Write RTC time by UART port ...

#2 Post by Darklakebridge78 » 02 Apr 2021 12:20

Mikroe team, any help? :(
MikroC PRO for PIC, MikroC PRO for dsPIC, MikroC PRO for PIC32, MikroC PRO for ARM, Visual TFT, Visual GLCD,
http://www.teolab.it

Darklakebridge78
Posts: 136
Joined: 12 May 2007 14:04
Location: Italy
Contact:

[SOLVED] Re: Write RTC time by UART port ...

#3 Post by Darklakebridge78 » 07 Apr 2021 20:56

I solved my problem using interrupt on UART1. :-)
MikroC PRO for PIC, MikroC PRO for dsPIC, MikroC PRO for PIC32, MikroC PRO for ARM, Visual TFT, Visual GLCD,
http://www.teolab.it

Post Reply

Return to “mikroBasic PRO for PIC32 General”