UART Rx problem using dsPic30F2011

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Ricard
Posts: 5
Joined: 25 Aug 2009 21:52

UART Rx problem using dsPic30F2011

#1 Post by Ricard » 25 Aug 2009 22:09

Hi,

I'm new in the forum.

A few days ago I decided to get this dsPic30 family and I started with MikroBasic with fast results.

But now, playing with UART, I totally stucked receiving data. I can send bytes but I'm totally uncapable for receive it.

I mounted a RS-232 interface connected to my PC. Removing the Pic and connecting Tx pin to Rx pin I can receive the echo in myPC. This means that the RS-232 interface is running properly.

I tryed to send data with UART_Write_Char() and works perfect.

But I never received a byte using UART_Read_Char()

Anyone knows if there is a limitation with MikroBasic and dsPic30F2011 ?
Maybe this Pic works in Rx inverted mode?

Here, the simple code to echo myPC:

Many thanks!

Code: Select all

program Test

dim rx1 as word

main:
  Uart1_Init(9600)
  while TRUE
    if Uart1_Data_Ready = 1 then
      rx1 = Uart1_Read_Char()
      Uart1_Write_Char(rx1)
    end if
  wend
end.

User avatar
nikola.kostic
mikroElektronika team
Posts: 433
Joined: 11 Aug 2009 12:12

#2 Post by nikola.kostic » 26 Aug 2009 13:19

Hi Ricard,

I tested your code on EASYdsPIC4 board using dsPIC30F2011 chip. I had to add one line of code to get UART working.

Try using this code:

Code: Select all

program Test

dim rx1 as word

main:

   ADPCFG = $FFFF   'I added this line

  Uart1_Init(9600)
   while TRUE
    if Uart1_Data_Ready = 1 then
      rx1 = Uart1_Read_Char()
      Uart1_Write_Char(rx1)
    end if
  wend
end.

Ricard
Posts: 5
Joined: 25 Aug 2009 21:52

#3 Post by Ricard » 26 Aug 2009 14:17

Great Nikola! It works!

As I can know this flags are to select analog/digital pins, but I asumed that Uart_Init() do that for me. I read some documentation explaining that this function sets the proper input output pins and that is not necessary do this manually.

Many thanks!

Ricard.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#4 Post by p.erasmus » 26 Aug 2009 14:44

yes it sets the pins related to the UART not the selection of pins as Digital or analog that you must do
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

Ricard
Posts: 5
Joined: 25 Aug 2009 21:52

#5 Post by Ricard » 27 Aug 2009 22:08

Ok, It is.

I'm was confused because the Tx pin works without changing ADPCFG register, even if this pin is an analog input also, like Rx pin.

Really, it's a litte confused.

Many thanks,

ricard.

Ricard
Posts: 5
Joined: 25 Aug 2009 21:52

Hang problem using Uart

#6 Post by Ricard » 29 Aug 2009 00:29

Hi again!

I have other question/problem

I write this function to get bytes from Uart

Code: Select all

sub function Read() as byte
  Loop:
    if Uart_Data_Ready()=0 then goto Loop end if
    result = Uart_Read_Char()
end sub
and this procedure to call the function and parse the received byte

Code: Select all

sub procedure Echo()
  dim In as byte
  Loop:
    In=Read()
    select case In
        case 1 'I will put other aditional code here
    end select
    goto Loop
end.
The program works but every 10 seconds (more or less) the program hangs and the Pic makes a Reset.

Any ideas?

Many thanks,

Ricard.

Ricard
Posts: 5
Joined: 25 Aug 2009 21:52

#7 Post by Ricard » 29 Aug 2009 15:56

Ops!

I found the problem, it was in one configuration bit. I need to be carefully with this little things :)
Hasta la próxima!

Ricard.

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”