Mikromedia for DSPic33EP

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Mikromedia for DSPic33EP

#1 Post by orpheedulogis » 31 Oct 2014 17:00

Hi all

I'm experiencing a problem on UART communication at low speed (1200 bauds)

On higher speeds (2400...9600 bauds) I can read correct incoming datas but at 1200 bauds datas become wrong.

here is my code



main:

Code: Select all

  
...
  CLKDIVbits.PLLPRE=0;  
  PLLFBD=68;          
  CLKDIVbits.PLLPOST=0;
//here freq=140Mhz

  PPS_Mapping(67, _INPUT, _U1RX);   // RP67=RD3=Rx1  
  PPS_Mapping(65, _OUTPUT, _U1TX);  // RP65=RD1=Tx1
  PPS_Mapping(97, _INPUT, _U2RX);   // RP97=RF1=Rx2
  PPS_Mapping(96, _OUTPUT, _U2TX);  // RP96=RF0=Tx2

  Delay_ms(100);
  UART2_Init_Advanced(1178, _UART_8BIT_NOPARITY, 1, _UART_LOW_SPEED); //at this baud rate, most of char are received
  delay_ms(100);
  //
  LigneTFT1=1;
  ColonneTFT=12;
  
  Start_TP();
  Start_screen();
  
  U2MODEbits.UARTEN=1; 
  IEC1bits.U2RXIE=1;   
  IFS1bits.U2RXIF=0;  
...
Interrupt code:

Code: Select all

void Rx2Interrupt() iv Rx2IntAdr
{
  unsigned int x1;
  char Txt1[3];
  Txt1[0]=UART2_Read() & 0x7F ;  //because I'm working on 7 bits I removed bit7 
  Txt1[1]=0;
  WriteOnTFT (txt1,LigneTFTx,LigneTFTy,CL_RED); // to display on TFT. Notice even if this line deplaced away(with long time timer interrupt) the problem is the same
  IFS1bits.U2RXIF=0;
}
For tests, I just send datas from USART terminal with a FT232 USB cable.

[/code]
Last edited by orpheedulogis on 04 Nov 2014 19:40, edited 1 time in total.

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: Mikromedia for DSPic33EP

#2 Post by orpheedulogis » 04 Nov 2014 09:10

I found the solution:

Code: Select all

   
U2MODE.BRGH = 1;
 U2BRG = 832;

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Mikromedia for DSPic33EP - UART problem

#3 Post by orpheedulogis » 04 Nov 2014 13:56

... and it doesn't work anymore ! :evil:

So, on Mikromedia for dsPic33EP board, there is a problem for receiving datas at 1200 bauds: it works for 2 or 3 datas, it doesn't work for more.
I tested U1MODE.BRGH = 0; U1BRG = 207; and U1MODE.BRGH =1; U1BRG = 832; . I also tested modifing speed a little (1198-1202 bauds).
Impossible to receive correctly datas.
With same software but at higher speeds (without modifing U1xBrg) I receive all datas.

is someone able to give me an working example for 1200 bauds communication, using interrupt ?

Thanks

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Mikromedia for DSPic33EP

#4 Post by filip » 05 Nov 2014 13:44

Hi,

Did you check the generated baud rate error percentage for the desired baud rate ?

Regards,
Filip.

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: Mikromedia for DSPic33EP

#5 Post by orpheedulogis » 05 Nov 2014 14:37

Thanks for help

For one case I have BRG=832 instead correct value 832.3333 so error equal 0.04%

I would be very happy if someone could test to verify if it work at a low speed like that.

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: Mikromedia for DSPic33EP

#6 Post by orpheedulogis » 10 Nov 2014 16:18

Any news ?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Mikromedia for DSPic33EP

#7 Post by filip » 12 Nov 2014 11:20

Hi,

For

Code: Select all

UART2_Init_Advanced(1200, _UART_8BIT_NOPARITY, _UART_ONE_STOPBIT, _UART_LOW_SPEED); 
I get U2BRG = 3645 (U2MODE.BRGH = 0) and the interrupt works fine :

Code: Select all

char uart_rd;
char cnt;

// Interrupt routine
void interrupt() iv IVT_ADDR_U2RXINTERRUPT {
  uart_rd=UART2_Read();
  cnt = 1;
  U2RXIF_bit = 0;                      // ensure interrupt not pending
}

void main() {
  // Setting output frequency to 140MHz
  PLLFBD = 68;             // PLL multiplier M=70
  CLKDIV = 0x0000;         // PLL prescaler N1=2, PLL postscaler N2=2

  ANSELA = 0x00;           // Convert all I/O pins to digital
  ANSELB = 0x00;
  ANSELC = 0x00;
  ANSELD = 0x00;
  ANSELE = 0x00;
  ANSELG = 0x00;

  PPS_Mapping(108, _INPUT,  _U2RX);              // Sets pin RP108 to be Input, and maps U2RX to it
  PPS_Mapping(109, _OUTPUT, _U2TX);              // Sets pin RP109 to be Output, and maps U2TX to it

  UART2_Init_Advanced(1200, _UART_8BIT_NOPARITY, _UART_ONE_STOPBIT, _UART_LOW_SPEED); //at this baud rate, most of char are received
  Delay_ms(100);                  // Wait for UART module to stabilize

  URXISEL_1_U2STA_bit = 0;
  NSTDIS_bit = 1;                      // no nesting of interrupts
  U2RXIF_bit = 0;                      // ensure interrupt not pending
  U2RXIE_bit = 1;                      // enable intterupt

  while (1) {                     // Endless loop
    if (cnt == 1) {
      cnt = 0;
      UART2_Write(uart_rd);       // and send data via UART
    }
  }
}
Regards,
Filip.

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: Mikromedia for DSPic33EP

#8 Post by orpheedulogis » 12 Nov 2014 17:14

Here is my code.
At 1200 for "VitesseUart" I just can send 3 flowwing ASCII code with rare errors. If I send more than 3 codes I have many errors.

At 2400 or higher speed I have NO error, even with a long string !

Code: Select all

#define VitesseUart1 1200
#define VitesseUart2 1200

//------------------------------------------------------------
// UART configuration

  UART1_Init_Advanced(VitesseUart1, _UART_8BIT_NOPARITY, 1, _UART_LOW_SPEED); //ATTENTION: normalement 7 bits + parité + 1 bit stop
  UART2_Init_Advanced(VitesseUart2, _UART_8BIT_NOPARITY, 1, _UART_LOW_SPEED); //ATTENTION: normalement 7 bits + parité + 1 bit stop
  delay_ms(500);
  U1MODE.UARTEN=1;     
  IEC0bits.U1RXIE=1;   
  IFS0bits.U1RXIF=0;  
  U2MODEbits.UARTEN=1; 
  IEC1bits.U2RXIE=1;  
  IFS1bits.U2RXIF=0;  

  Rx1NumLigne=0;
  Rx1LigneComplete=0;
  Rx1TempsControleReponse=0;
  FlagFinControleU1=0;
  ExRx1Index=0;
  if (VitesseUart1==1200)
  {
    U1MODE.BRGH = 0;
    U1BRG = 3645;
  }

//------------------------------------------------------------

void Rx1Interrupt() iv Rx1IntAdr

{
    if (Rx1CaractLu==Rx1Sep) // data end char for line
    {
        Rx1LigneComplete=Rx1NumLigne;// flag
        if (Rx1Index>0) 
        {
           Rx1TempsControleReponse=0; // reset control for answer time
           Rx1Car[Rx1NumLigne][Rx1Index]=0; // stop string 
           Rx1Index=0;
           Rx1NumLigne++;
           if (Rx1NumLigne>=Rx1NbreLignes) { Rx1NumLigne=0;}
        }
    }
    else
   {
      if (Rx1CaractLu >0x0D) // doesn't memorize low ascii code
      {
        Rx1Car[Rx1NumLigne][Rx1Index] = Rx1CaractLu; // memorize char (line,index)
        Rx1Index++;
        if(Rx1Index>Rx1NbreCarMaxLigne) {Rx1Index=Rx1NbreCarMaxLigne; } //security for line size
        Rx1Car[Rx1NumLigne][Rx1Index] = 0; // stop string
      }
   }
    IFS0bits.U1RXIF=0;
}

//------------------------------------------------------------

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Mikromedia for DSPic33EP

#9 Post by filip » 13 Nov 2014 15:50

Hi,

Please, can you try the code I posted and see if it works ?

Regards,
Filip.

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: Mikromedia for DSPic33EP

#10 Post by orpheedulogis » 13 Nov 2014 17:19

I will see ... I think I tried already it but not sure for result.

I tried my same code on STM32 (EasyMx Pro v7) and it work perfectly, even if 1200 or 9600 bauds, so I decided to change dsPic to Stm32. There is probably a little problem on DsPic, like if time wasn't correctly setted for 1200 bauds.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”