Microcontroller › PIC › Problem with EUSART module pf PIC16F1933
- This topic has 0 replies, 1 voice, and was last updated 9 years, 4 months ago by Debou Alexander.
-
AuthorPosts
-
April 22, 2015 at 4:11 pm #3634Debou AlexanderParticipant
Hey everyone!
I have a problem with the EUSART receiver module of my PIC 16F1933. I use this module to receive data trought bluetooth. First I tried to use the MikroC library for UART but it also didn't work. Then I tried to initialise the module by myself like the code below. Can anyone find the problem? The bluettoh module receives the data correctly, so this is not the problem. The Baudrate is 9600
With regards
Alexander
unsigned char data_Rx
char i,j=0;/*==============================================================================
*
==============================================================================*//******************************************************************************
*EUSART_Init_9600*8bit data
*Instellen BAUDRATE
*TXSTA.SYNC = 0 | *BR = 9600
*TXSTA.BRGH = 1 | *Value SPBRGL = 25
*BAUDCON.BRG16 = 0 | *Fault = 16%
*SPBRGL = 25 | *FOSC = 4MHz
*BAUDCON.SCKP = 0
*BAUDCON.WUE = 0
*BAUDCON.ABDEN = 0*Instellen EUSART
*TRISC.B7 = 1
*RCSTA.SPEN = 1
*RCSTA.RX9 = 0
*RCSTA.ADDEN = 0
*RCSTA.CREN = 1
RCSTA.SREN = 0*TXSTA.SYNC=0
*TXSTA.BRGH=1
*BAUDCON=0b00000000=0x00
*SPBRGL = 25
*SPBRGH = 0
*RCSTA = 0b10010000
******************************************************************************/
void EUSART_Init_9600()
{
TXSTA.SYNC=0;
TXSTA.BRGH=1;
BAUDCON=0x00;
SPBRGL = 25;
SPBRGH = 0;
RCSTA = 0b10010000;
}/******************************************************************************
*EUSART_read()*returns RCREG (char)
******************************************************************************/
char EUSART_Read()
{
return RCREG;
}/******************************************************************************
*EUSART_read_Text(char *Output, unsigned int length)*returns RCREG (char)
******************************************************************************/
void EUSART_Read_Text(char *Output, unsigned int length)
{
int i;
for( i=0;i<length;i++) Output = RCREG;
}/******************************************************************************
*Interrupt routine
******************************************************************************/
void interrupt()
{
INTCON.GIE=0;
if(PEIE.RCIF)
{
EUSART_Read_Text(data_Rx,5);
i++;
if(i==5)
{
i=0;
}data_Rx = EUSART_Read();
}
INTCON.GIE=1;
}/******************************************************************************
*Hoofdprogramma
******************************************************************************/
void main()
{
ANSELA=0;
ANSELB=0;
TRISC.B7=1; // Rx pin as inputTRISB.B0=0;
TRISB.B5=0;EUSART_Init_9600();
Delay_ms(100);
PIE1.RCIE = 1;
INTCON.PEIE=1;
INTCON.GIE=1;
while(1)
{
data_Rx=UART1_Read();
if (data_Rx ==0xAA)
{
PORTB.B0 = 1;
Delay_ms(2000);
PORTB.B5 = 1;
Delay_ms(2000);
PORTB.B0 = 0;
Delay_ms(2000);
PORTB.B5 = 0;
}
}
}
/*============================================================================
*Einde Programma
============================================================================*/ -
AuthorPosts
- You must be logged in to reply to this topic.