Im Interrupt funktionen benutzen?


ich habe hier eine isr die immer ausgelöst wird wenn ein zeichen der seriellen schnittstelle zu lesen ist.
eingehängt ist diese isr(uart2_rx_irq).
ich hoffe es richtig zu verstehen, das ich dann im udr2 register den wert lesen kann.
code: [select]


volatile uint8_t  mpngrcinput::raw_data[34]
...
/* isr srlx on uart2 */
void mpngrcinput::_serial_srlx_isr(void)
{
uint8_t wert;
static uint8_t ctr;
         wert=udr2;
        if (wert==0xa2) ctr=0;
        if (ctr<=34) {
        raw_data[ctr]=wert;          
            ctr++
                   }
             if (ctr=34)
                    {
                   // telegramm komplett, hier müsste ein crc check erfolgen etwa so
                uint16_t    crc=0;
                                        for(i=0; i<=32; i++)          
                                                 crc=crc16(crc,raw_data[i]);
 
                           uint16_t   checkcrc=(raw_data[33]<<8 | raw_data[34]);  
                                         if (crc==checkcrc) {
                                                              // daten in ordnung
                                                                           
                                                                          }
                       }      


}


die funktion  sollte ab startbyte 0xa2 ein 35 byte großes array füllen.
wenn das array voll ist, muss ich aus den ersten 33 byte ein crc berechenen.
die funktion habe ich schon in einem ähnlichen projekt verwendet und funktioniert

code: [select]

uint16_t crc16(uint16_t crc, uint8_t value)
{
uint8_t i;
crc = crc ^ (uint16_t)value<<8;
for (i=0; i<8; i++)
   {
     if (crc & 0x8000)
         crc=crc << 1 ^0x1021;
         else
          crc = crc << 1;
   }
   return crc;
}



aber:
kann oder darf ich in der isr die funktion checkcrc aufrufen ? und wenn ja wenn muss diese volatile definiert sein ?
oder ist der code in der isr generell zu umfangreich ?

grundsätzlich geht sowas. und die funktion sieht auch nicht teuer aus. im schlimmsten fall nimmst du eben die baudrate runter auf 9600 baud.  und weil es eine funktion ohne seiteneffekte ist brauchst du auch nirgends volatile. volatile brauchst du eigentlich nur bei (globalen) variablen auf denen du in interrupts seiteneffekte erzeugst.


Arduino Forum > International > Deutsch (Moderator: uwefed) > Im Interrupt funktionen benutzen?


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support