Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with uart dspic30f4011

Status
Not open for further replies.

lopex

Junior Member level 1
Joined
Jan 16, 2008
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,399
u1brg

I'm using dspi30f4011, with a mplab C30, cristal a 4MHz, 9600 baud rate.
Problem: not get anything in hiperterminal.
Thanks,
Lopex
code:
#include <p30f4011.h>
#include <uart.h>
#include <stdio.h>
#include <stdlib.h>
#include <ports.h>
#include <stdlib.h>
#include <timer.h>
#include <p30fxxxx.h>

int main( void );
void conf_uart(void);
void Inicializacao(void);


_FOSC(CSW_FSCM_OFF & XT_PLL16);
_FWDT(WDT_OFF);
_FBORPOR(PBOR_OFF & MCLR_EN);
_FGS(CODE_PROT_OFF);

int main( void )
{
unsigned char a[]="test";
unsigned int b;

Inicializacao();
LATDbits.LATD0=1; //led 1
b=(unsigned int) a;
putsUART2(b);
LATDbits.LATD1=1; //led 2

}
void Inicializacao(void)
{

TRISD= 0xC;
TRISF= 0x17; // os portos RF6/SCK1 e RF5/U2TX e RF3 são saidas, as restantes estão em alta impedancia
TRISE = 0x120;
TRISC = 0x0000;

conf_uart();
}

void conf_uart(void){

unsigned int U2MODEvalue, U2STAvalue;
int baud;

U2MODEvalue = UART_EN & UART_IDLE_CON & UART_RX_TX & UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT & UART_1STOPBIT;

U2STAvalue = UART_INT_TX_BUF_EMPTY & UART_TX_PIN_NORMAL & UART_TX_ENABLE & UART_INT_RX_3_4_FUL & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR;

baud = 25;

ConfigIntUART2(UART_RX_INT_EN & UART_RX_INT_PR4 & UART_TX_INT_DIS);

OpenUART2( U2MODEvalue, U2STAvalue, baud);

}
 

#include <p30f4011.h>

hi! Now in English

code:
#include <p30f4011.h>
#include <uart.h>
#include <stdio.h>
#include <stdlib.h>
#include <ports.h>
#include <stdlib.h>
#include <timer.h>
#include <p30fxxxx.h>

int main( void );
void conf_uart(void);
void Inicializacao(void);


_FOSC(CSW_FSCM_OFF & XT_PLL16);
_FWDT(WDT_OFF);
_FBORPOR(PBOR_OFF & MCLR_EN);
_FGS(CODE_PROT_OFF);

int main( void )
{
unsigned char a[]="test";
unsigned int b;

Inicializacao(); //Start boot
LATDbits.LATD0=1; //led 1
b=(unsigned int) a; //cast
putsUART2(b);
LATDbits.LATD1=1; //led 2

}
void Inicializacao(void) //Start boot
{

TRISD= 0xC; // outputs for leds
TRISF= 0x17; // ports RF6/SCK1 and RF5/U2TX and RF3 outputs
TRISE = 0x120;
TRISC = 0x0000;

conf_uart();
}

void conf_uart(void){

unsigned int U2MODEvalue, U2STAvalue;
int baud;

U2MODEvalue = UART_EN &
UART_IDLE_CON &
UART_RX_TX &
UART_DIS_LOOPBACK &
UART_DIS_ABAUD &
UART_NO_PAR_8BIT &
UART_1STOPBIT;

U2STAvalue = UART_INT_TX_BUF_EMPTY &
UART_TX_PIN_NORMAL &
UART_TX_ENABLE &
UART_INT_RX_3_4_FUL &
UART_ADR_DETECT_DIS &
UART_RX_OVERRUN_CLEAR;

baud = 25; // (4Mz/(16*9600)-1)

ConfigIntUART2(UART_RX_INT_EN &
UART_RX_INT_PR4 &
UART_TX_INT_DIS);

OpenUART2( U2MODEvalue, U2STAvalue, baud);

}

Thanks
 

uart c30

Code:
b=(unsigned int) a; //cast
putsUART2(b);

let me state at the beginning, that I do not program in C (i prefer asm), so I might not know that function putsUART(), but it seems to me, that you feed the function with an direct address to your string. should it be like that?

0x41 0x56 0x45!!
 

    lopex

    Points: 2
    Helpful Answer Positive Rating
configintuart2

hi!

Is the first time I write a program for dspic in C30, I used to write a program for pic18f whith C18 using the command usart...

In dspic the command is uart, the function is:

void putsUART2(unsigned int *buffer) __attribute__ ((section (".libperi")));

Thanks
 

dspic 30f 4011 uart

Hi!
I have not worked with dspic30F4011 but i am currently working on dspic33FJ12MC202 and below is the initilisation code for my USART. I am not using any interrupts but using polling method.

//*******************************************************************
//The function initilises the USART for communications.
//*********************************************************************
void InitUART(void)
{
// Initialize the UART1 for BAUD = 115,200

U1MODE = 0x8008; //Enable USART module with high baurd rate
U1STA = 0x0000;
U1BRG = 7; //115.2 Kbaud at 7.3720 MHz crystal(No PLL)

U1STAbits.UTXEN = 1; // Enable transmission
}

so my advice for you is to change your code to this from so that it is easy to understand. Only then people will be able to help you.

Hope this helps.
Best Regards
waseem
 

    lopex

    Points: 2
    Helpful Answer Positive Rating
uart dspic 30f4011

hi!

U1BRG = 7; //115.2 Kbaud at 7.3720 MHz crystal(No PLL)

how you calculate the U1BRG?

thanks!
 

u1brg baudrate

Hi!

With the BRGH = 1;(High baud rate) the formula is

U1BRG = (Fosc/4 * Buad Rate) - 1;

With BRGH = 0;(Low Baud rate) the fromula is

U1BRG = (Fosc/16 * Buad Rate) - 1;

If this does not give a rounded value then you have to check wheather rounding it will not produce errors.

Note that if you are using an external crystal as the oscillator without any PLL then Fosc = crystal frequency/2;

All these calculation are explained in detail in the data sheets.

Hope this solves your problem.

Best Regards.
 

    lopex

    Points: 2
    Helpful Answer Positive Rating
dspic30f4011 uart string

what is the max reasonable baud rate error allowed? is error < 1% acceptable?

0x41 0x56 0x45!!
 

    lopex

    Points: 2
    Helpful Answer Positive Rating
dspic30f4011 rf6

Hi Freddie!
I am not sure but i think the <1% error is ok.
I personally try to keep it below 0.16%.

Regards.
 

    lopex

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top