packet streaming

General discussion on mikroC.
Author
Message
denisF
Posts: 1
Joined: 06 Aug 2008 16:10

Critical section

#46 Post by denisF » 06 Aug 2008 16:18

Hi!
rxdata is shared between your main() and your interupt().
May be you have to protect your code ?

Code: Select all

main()
{
	INTCON.GIE	= 0;			// Begin critical section

        // work with rxdata here

	INTCON.GIE	= 1;			// End critical section
}
Cheers

atommic22
Posts: 24
Joined: 17 May 2008 12:39

#47 Post by atommic22 » 07 Aug 2008 09:51

I'm not sure if that would make any difference but I will try it... it may get rid of that effect of using rxdata in the two "IF" statements.

Bonca
Posts: 319
Joined: 18 Mar 2009 07:55

Re: packet streaming

#48 Post by Bonca » 07 Jan 2011 15:33

Hi,
I am working on a similar data streaming. The problem is on the receiver side. I connected a led to be indicated if two data bytes and their checksum are ok. I have checked the digital signal on receiver side and the picture shows it is ok too. Yellow is the transmitter digital input, blue is the receiver digital output.
10ms_delay_good.jpg
10ms_delay_good.jpg (37.92 KiB) Viewed 1604 times
This is the transmitter code (12F683):

Code: Select all

Soft_UART_Init(&GPIO, 4, 5, 1200, 0);       // receiver data rate fmax=2kHz => 1200
    delay_ms(1000);

    while(1){

        Soft_UART_Write(0xAA);    // dummy
        delay_ms(10);             // after 30ms receiver output goes to low (???)
        Soft_UART_Write(0x55);
        delay_ms(10);
        Soft_UART_Write(0xAA);
        delay_ms(10);
        Soft_UART_Write(0x55);
        delay_ms(10);
        Soft_UART_Write(0x05);    // start_byte
        delay_ms(10);
        Soft_UART_Write(0x03);    // data_byte1
        delay_ms(10);
        Soft_UART_Write(0x04);    // data_byte2
        delay_ms(10);
        Soft_UART_Write(0x07);    // checksum_byte = data_byte1 + data_byte2
        delay_ms(10);

        GPIO.F2 = ~GPIO.F2;       // indicates end of cycle
    }
This is the receiver code (18F2520):

Code: Select all

UART1_Init(1200);
    delay_ms(100);

    while(1){
        while(start_byte != 0x05){               // until 0x05 comes...
            if(UART1_Data_Ready() == 1){         // start_byte
                start_byte = UART1_Read();
            }
        }

        if(UART1_Data_Ready() == 1){             // data_byte1
            data_byte1 = UART1_Read();
        }
        
        if(UART1_Data_Ready() == 1){             // data_byte2
            data_byte2 = UART1_Read();
        }
        
        if(UART1_Data_Ready() == 1){             // checksum_byte
            checksum_byte = UART1_Read();
        }
        
        if(checksum_byte == (data_byte1 + data_byte2)){    // simple error checking
            LATB.F0 = ~LATB.F0;                  // indicates if no error in data transfer
        }

        start_byte = 0;
    }
The problem is that receiver led always changes its state, no matter if error checking good or not. What is wrong with the code? I use mikroC 4.6.

Bonca

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

Re: packet streaming

#49 Post by drdoug » 07 Jan 2011 16:56

I think you are just moving through your code and not reading any new data. Change your
r

Code: Select all

if(uart1 ready)
To

Code: Select all

while(!uart1 ready)
This will create a blocking code but can be a next step in your project. There are still other issues to resolve as well. Ultimately it will be better to use interrupts.

Bonca
Posts: 319
Joined: 18 Mar 2009 07:55

Re: packet streaming

#50 Post by Bonca » 07 Jan 2011 21:34

Hi drdoug,
thank you for fast reply. I realized, I answered an old post... I open this here:
http://www.mikroe.com/forum/viewtopic.php?f=88&t=28602

Bonca

Post Reply

Return to “mikroC General”