UART Read

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
basti1000
Posts: 1
Joined: 11 Jan 2017 13:38

UART Read

#1 Post by basti1000 » 11 Jan 2018 18:11

Hello,

I would like to read out the compass module CMPS11 via RS232, I send the command 0x13 then the module sends back 2 bytes. How can I read these 2 bytes?

Code: Select all

UART1_Write(0x13)
    Delay_ms(100)
    if (UART1_Data_Ready() = 1) then
    re_high = UART1_Read()
    end if
    if (UART1_Data_Ready() = 1) then
    re_low = UART1_Read()
    end if
    angle=re_high*256
    angle= angle+re_low
this code does not work

thank you for your help

User avatar
marko.stankovic
mikroElektronika team
Posts: 108
Joined: 18 Dec 2017 15:44

Re: UART Read

#2 Post by marko.stankovic » 12 Jan 2018 12:10

Hi,

Since it is not MikroElektronika's product I did not have any contact with this module.
Did you try to look into the product's datasheet ? Maybe you can find some info there.
This is an example for our modules, maybe it can help you.

Code: Select all

  UART2_Init(9600)                     ' Initialize UART module at 9600 bps
  Delay_ms(100)                        ' Wait for UART module to stabilize

  UART2_Write_Text("Ready")
  UART2_Write(13)                      ' Line Feed
  UART2_Write(10)                      ' Carriage Return

  while (TRUE)                         ' Endless loop
    if (UART2_Data_Ready() <> 0) then  ' If data is received,
      uart_rd = UART2_Read()           ' read the received data,
      UART2_Write(uart_rd)             ' and send data via UART
    end if
  wend
Best Regards,
Marko Stankovic.

Post Reply

Return to “mikroBasic PRO for ARM General”