Skip to main content
added 49 characters in body
Source Link
Lundin
  • 22.2k
  • 1
  • 30
  • 83

Some bugs:

  • Arrays in C start at index zero. You write to index 1 to 8, instead of 0 to 7:

      i++;
      Rx_buf_F0[i] = ...
    
  • You should declare all variables shared between main and and ISR volatile to protect against incorrect compiler optimizations. Also, it would seem that you have no semaphores to protect rx_fifo_F0. Accesses to that variable will not be atomic, so if you have no semaphores you will get intermittent bugs where random garbage suddenly appears in that variable.

  • data is 4 bytes large yet you write to index 3 to 7.

      for(int k=3;k<7;k++)
      data[k]=Rx_buf_F0[k];
    

Might be more, but these are all severe bugs.

Some bugs:

  • Arrays in C start at index zero. You write to index 1 to 8, instead of 0 to 7:

      i++;
      Rx_buf_F0[i] = ...
    
  • You should declare all variables shared between main and and ISR volatile to protect against incorrect compiler optimizations. Also, it would seem that you have no semaphores to protect rx_fifo_F0. Accesses to that variable will not be atomic, so if you have no semaphores you will get intermittent bugs where random garbage suddenly appears in that variable.

  • data is 4 bytes large yet you write to index 3 to 7.

      for(int k=3;k<7;k++)
      data[k]=Rx_buf_F0[k];
    

Some bugs:

  • Arrays in C start at index zero. You write to index 1 to 8, instead of 0 to 7:

      i++;
      Rx_buf_F0[i] = ...
    
  • You should declare all variables shared between main and and ISR volatile to protect against incorrect compiler optimizations. Also, it would seem that you have no semaphores to protect rx_fifo_F0. Accesses to that variable will not be atomic, so if you have no semaphores you will get intermittent bugs where random garbage suddenly appears in that variable.

  • data is 4 bytes large yet you write to index 3 to 7.

      for(int k=3;k<7;k++)
      data[k]=Rx_buf_F0[k];
    

Might be more, but these are all severe bugs.

Source Link
Lundin
  • 22.2k
  • 1
  • 30
  • 83

Some bugs:

  • Arrays in C start at index zero. You write to index 1 to 8, instead of 0 to 7:

      i++;
      Rx_buf_F0[i] = ...
    
  • You should declare all variables shared between main and and ISR volatile to protect against incorrect compiler optimizations. Also, it would seem that you have no semaphores to protect rx_fifo_F0. Accesses to that variable will not be atomic, so if you have no semaphores you will get intermittent bugs where random garbage suddenly appears in that variable.

  • data is 4 bytes large yet you write to index 3 to 7.

      for(int k=3;k<7;k++)
      data[k]=Rx_buf_F0[k];