Autor Tema: dsPIC30F4011 UART RS232  (Leído 3374 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado pepescorpi

  • PIC10
  • *
  • Mensajes: 5
dsPIC30F4011 UART RS232
« en: 16 de Noviembre de 2012, 01:09:48 »
 :? :? :?estoy haciendo una transmisión de una lectura de un sensor pero me quede varado con la recepción no se si alguien me pueda apoyar!!!  se los agradecería mi codigo es este!!
//librerias
#include <p30f4011.h>


//definiciones
#define Led PORTBbits.RB0
#define FOSC 10000000  // 10Mhz
#define FCY (FOSC / 4)
#define BAUD_RATE 9600 // Slower baud rate chosen
#define UXBRG (((FCY / 16) / BAUD_RATE) -1)

//prototipo de funciones
void configura_IO(void);
void configura_timer2(void);
void configura_timer1(void);


//funcion principal
int main (void){
configura_IO();
configura_timer2();
configura_timer1();
// UART Setup
   U1BRG = UXBRG; // Establezce la velocidad de transmisión
   U1MODEbits.PDSEL = 0; // 8 datos bits, no paridad(sin paridad)
   U1MODEbits.STSEL = 0; // 1 stop bit (bit de parada)
   U1MODEbits.LPBACK = 0; // Desactivar el modo bucle
   U1MODEbits.ALTIO  = 0; // El uso alternativo UART TX & RX
   U1MODEbits.UARTEN = 1; // Habilitar UART módulo
      U1STAbits.UTXBRK = 0; //Borra los bits
   U1STAbits.UTXEN   = 1; // Habilitar UART transmision
while (1){
   Led=!Led;
   }
}

//implementacion de funciones
void configura_IO(void){
ADPCFGbits.PCFG0=1;//HABILITA PUERTOS DIGITALES

PORTBbits.RB0;//SALIDAS DIGITALES
TRISBbits.TRISB0=0; //SALIDA DIGITAL
}
void configura_timer2(void) {
/*T2CONbits.TON=0; //apaga el timer
T2CONbits.TSIDL=0; //trabajar en nivel alto
T2CONbits.TGATE=0; //trabajara como temporizador
T2CONbits.TCKPS=2; //seleccionar el preescalador 64
T2CONbits.T32=0; //HABIALITA AL 16BITS
T2CONbits.TCS=0*/ //UTILIZA LA FRECUENCIA INTERNA DEL RELOJ

T2CON=0;
T2CONbits.TCKPS=0;// ES LO MISMO QUE ESTA EN EL COMENTARIO;
TMR2=0;
PR2=50;

IEC0bits.T2IE=1; //habilita interrupciones
IPC1bits.T2IP=4; //PRIORIDAD 4
IFS0bits.T2IF=0; //bandera de interrupcion timer 2 borradas
T2CONbits.TON=1; //ENCENDER EL TIMER
   }

void configura_timer1(void) {
T1CONbits.TON=0; //apaga el timer
T1CONbits.TSIDL=0; //trabajar en nivel alto
T1CONbits.TGATE=1; //trabajara como acomulador
T1CONbits.TCKPS=2; //seleccionar el preescalador 64
T1CONbits.TCS=0; //UTILIZA LA FRECUENCIA externa DEL RELOJ
T1CONbits.TSYNC=0; //HABIALITA el reloj externo


IFS0bits.T1IF=0; //borrar bandera de interrupcion timer
IEC0bits.T1IE=1; //habilita interrupciones
IPC0bits.T1IP=1; //PRIORIDAD 1
T1CONbits.TON=1; //ENCENDER EL TIMER
TMR1=0;

   }
void __attribute__((interrupt, no_auto_psv)) _T2interrupt(void){
Led=!Led;
IFS0bits.T2IF=0;
}

  //rutinas de atencion a servicio a interrupciones(ISR)
void __attribute__((interrupt, no_auto_psv)) _T1interrupt(void){
IFS0bits.T1IF=0;
TMR1=0;


}

Desconectado pepescorpi

  • PIC10
  • *
  • Mensajes: 5
Re: dsPIC30F4011 UART RS232
« Respuesta #1 en: 16 de Noviembre de 2012, 15:35:00 »
CON ESTE CODIGO YA TENGO EL PULSO PERO LO QUE NO PUEDO ES VERLO EN LABVIEW NO SE SI PUEDEN VERIFICAR MI CODIGO GRACIAS....
//librerias
#include <p30f4011.h>
#include <uart.h>


//definiciones
#define Led PORTBbits.RB0
#define FOSC 10000000  // 10Mhz
#define FCY (FOSC / 4)
#define BAUD_RATE 9600 // Slower baud rate chosen
#define UXBRG (((FCY / 16) / BAUD_RATE) -1)

//prototipo de funciones
void configura_IO(void);
void configura_timer2(void);
void configura_timer1(void);
void configura_UART(void);

//funcion principal
int main (void){
configura_IO();
configura_timer2();
configura_timer1();
configura_UART();

while (1){
   Led=!Led;
   }
}

//implementacion de funciones
void configura_IO(void){
ADPCFGbits.PCFG0=1;//HABILITA PUERTOS DIGITALES

PORTBbits.RB0;//SALIDAS DIGITALES
TRISBbits.TRISB0=0; //SALIDA DIGITAL
}
void configura_UART(void){
// UART Setup
   U1BRG = UXBRG; // Establezce la velocidad de transmisión
   U1MODEbits.PDSEL = 0; // 8 datos bits, no paridad(sin paridad)
   U1STAbits.UTXISEL=1;//int.Cuando un caracter se transf.al reg. de despla.de trans. y como resultado el buffer se vacia
   U1MODEbits.UARTEN = 1; // Habilitar UART módulo
   U1STAbits.UTXEN   = 1; // Habilitar UART transmision
   U1MODEbits.STSEL = 0; // 1 stop bit (bit de parada)
   U1MODEbits.LPBACK = 0; // deshabilita el modo bucle
   U1MODEbits.ALTIO  = 0; // El uso alternativo UART TX & RX
   U1STAbits.UTXBF= 1; //Transmit está lleno
   U1STAbits.URXISEL=3;//indicador de interrupcion, se activa
   //cuando el bufer de recepcion esta lleno(es decir,tiene 4 caracteres de datos)
   U1STAbits.URXDA=0;// búfer de recepción está vacío
}
//TIMER temporizador
void configura_timer2(void) {
/*T2CONbits.TON=0; //apaga el timer
T2CONbits.TSIDL=0; //trabajar en nivel alto
T2CONbits.TGATE=0; //trabajara como temporizador
T2CONbits.TCKPS=2; //seleccionar el preescalador 64
T2CONbits.T32=0; //HABIALITA AL 16BITS
T2CONbits.TCS=0*/ //UTILIZA LA FRECUENCIA INTERNA DEL RELOJ

T2CON=0;
T2CONbits.TCKPS=0;// ES LO MISMO QUE ESTA EN EL COMENTARIO;
TMR2=0;
PR2=50;

IEC0bits.T2IE=1; //habilita interrupciones
IPC1bits.T2IP=4; //PRIORIDAD 4
IFS0bits.T2IF=0; //bandera de interrupcion timer 2 borradas
T2CONbits.TON=1; //ENCENDER EL TIMER
   }
//TIMER ACOMULADOR
void configura_timer1(void) {
T1CONbits.TON=0; //apaga el timer
T1CONbits.TSIDL=0; //trabajar en nivel alto
T1CONbits.TGATE=1; //trabajara como acomulador
T1CONbits.TCKPS=2; //seleccionar el preescalador 64
T1CONbits.TCS=0; //UTILIZA LA FRECUENCIA externa DEL RELOJ
T1CONbits.TSYNC=0; //HABIALITA el reloj externo


IFS0bits.T1IF=0; //borrar bandera de interrupcion timer
IEC0bits.T1IE=1; //habilita interrupciones
IPC0bits.T1IP=1; //PRIORIDAD 1
T1CONbits.TON=1; //ENCENDER EL TIMER
TMR1=0;

   }
void __attribute__((interrupt, no_auto_psv)) _T2interrupt(void){
Led=!Led;
Led=!Led;
IFS0bits.T2IF=0;
}

  //rutinas de atencion a servicio a interrupciones(ISR)
void __attribute__((interrupt, no_auto_psv)) _T1interrupt(void){
IFS0bits.T1IF=0;
TMR1=0;
U1TXREG=TMR1;   
}


Desconectado Sispic

  • Moderador Local
  • PIC24H
  • *****
  • Mensajes: 1700
    • winpic800
Re: dsPIC30F4011 UART RS232
« Respuesta #2 en: 16 de Noviembre de 2012, 16:27:57 »
Yo tampoco consigo verlo en LABVIEW

Desconectado pepescorpi

  • PIC10
  • *
  • Mensajes: 5
Re: dsPIC30F4011 UART RS232
« Respuesta #3 en: 19 de Noviembre de 2012, 20:36:37 »
al parecer eran unos pequeños detalles , ahora necesito que con el pwm disminuya el pulso o aumente cada vez que haya una diferente lectura del sensor
uu!! HELP!!
//librerias
#include <p30f4011.h>



//definiciones
#define Led PORTBbits.RB0
#define FOSC 10000000  // 10Mhz
#define FCY (FOSC / 4)
#define BAUD_RATE 9600 // Slower baud rate chosen
#define UXBRG (((FCY / 16) / BAUD_RATE) -1)

//prototipo de funciones
void configura_IO(void);
void configura_timer2(void);
void configura_timer1(void);
void configura_uart(void);

//funcion principal
int main (void){
configura_IO();
configura_timer2();
configura_timer1();
configura_uart();

while (1){
   
   }
}

//implementacion de funciones
void configura_IO(void){
ADPCFG=1;//HABILITA PUERTOS DIGITALES
PORTBbits.RB0;//SALIDAS DIGITALES
TRISB=0; //SALIDA DIGITAL
}
//TIMER temporizador
void configura_timer2(void) {
T2CONbits.TON=0; //apaga el timer
T2CONbits.TSIDL=0; //trabajar en nivel alto
T2CONbits.TGATE=0; //trabajara como temporizador
T2CONbits.TCKPS=0; //seleccionar el preescalador 1:256
T2CONbits.T32=0; //HABIALITA AL 16BITS
T2CONbits.TCS=0;  //UTILIZA LA FRECUENCIA INTERNA DEL RELOJ
// es igual a poner T2CON=0;
// y solo el que es diferente T2CONbits.TCKPS=2;
TMR2=0;
PR2=50;
IFS0bits.T2IF=0; //bandera de interrupcion timer 2 borradas
IEC0bits.T2IE=1; //habilita interrupciones
IPC1bits.T2IP=4; //PRIORIDAD 4
T2CONbits.TON=1; //ENCENDER EL TIMER
   }
//TIMER ACOMULADOR
void configura_timer1(void) {
T1CONbits.TON=0; //apaga el timer
T1CONbits.TSIDL=0; //trabajar en nivel alto
T1CONbits.TGATE=1; //trabajara como acomulador
T1CONbits.TCKPS=3; //seleccionar el preescalador 1:256
T1CONbits.TCS=0; //UTILIZA LA FRECUENCIA externa DEL RELOJ
T1CONbits.TSYNC=0; //HABIALITA el reloj externo


IFS0bits.T1IF=0; //borrar bandera de interrupcion timer
IEC0bits.T1IE=1; //habilita interrupciones
IPC0bits.T1IP=1; //PRIORIDAD 1
T1CONbits.TON=1; //ENCENDER EL TIMER
   }
void configura_uart(void){
// UART Setup
   U1STAbits.UTXEN   = 0; // Habilitar UART transmision
   U1BRG = 15; // Establezce la velocidad de transmisión
   U1MODEbits.PDSEL = 0; // 8 datos bits, no paridad(sin paridad)
   U1MODEbits.STSEL = 0; // 1 stop bit (bit de parada)
   U1MODEbits.ALTIO  = 1; // Use alternate UART TX & RX
   IFS0bits.U1TXIF=1; //habilita interrupcion
   IPC2bits.U1TXIP=2; //prioridad de interrupcion    
   U1MODEbits.UARTEN =1; // Habilitar UART módulo
   IFS0bits.U1TXIF=0; //se borra la bandera de interrupcion
   U1STAbits.UTXISEL=1;//int.Cuando un caracter se transf.al reg. de despla.de trans. y como resultado el buffer se vacia
   
}
//interrupciones
 //rutinas de atencion a servicio a interrupciones(ISR)
void __attribute__((interrupt, no_auto_psv)) _T2interrupt(void){
Led=!Led;
IFS0bits.T2IF=0;// se baja la bandera xq ya se atendio la interrupcion
}
void __attribute__((interrupt, no_auto_psv)) _T1interrupt(void){
TMR2=0;
U1STAbits.UTXEN=1;
U1TXREG=TMR1;
IFS0bits.T1IF=0;
TMR1=0;}