If you use code tags and indent your code it becomes much easier to read (and debug).
I.E.
Code:
If dio0 = 1 Then 'DIO0 goes high from SX1278 when data has been received and ready.
irqflags = spi_read_reg_func(r_regirqflags, irqflags) 'CHECK SYNTAX (SUBROUTINE)
regirqflags_validheader = irqflags.4 'Mask
regirqflags_payloadcrcerror = irqflags.5 'mask
If regirqflags_validheader = 1 Then
If regirqflags_payloadcrcerror = 0 Then
rxsize = spi_read_reg_func(r_regrxnbbytes, fiforxbytesnb)
While x < rxsize
read_reg_spi = spi_read_reg_func(r_regfiforxbaseaddr, fiforxbaseaddr)
x = x + 1
Wend 'IS THIS in the correct place?????????????????????
Endif
Endif
Endif
As you can see from the above indenting, the Wend is in the correct place.
BTW, I don't see where x is initialised.
Mike.