AnsweredAssumed Answered

STM8S105 direct register access, pointers...

Question asked by cros.alexis on Nov 25, 2015
Latest reply on Nov 27, 2015 by cros.alexis
Hello everybody,  I'm working on the STM8 discovery board to implement some application which controls the STM8's GPIOs from an SPI master.
The code relies on SPI interrupts. I would like the master sends the address of the targeted register (15 bits) and a 16th one (MSB) which indicates the access mode (Read or Write).
I can't solve an issue about pointers. The interrupt code is the following :

#define ACCESS_BIT 7
#define READ_INPUT_ID 0x50

char cpt, temp, add;
uint8_t mode_add_MSB, add_LSB;
bool access; // '1' = W, '0' = R

INTERRUPT_HANDLER(SPI_IRQHandler, 10)
{    
    if (SPI_GetITStatus(SPI_IT_RXNE)!=RESET)
    {
        if(cpt==0) // Reception of the access mode bit and the 7 MSB address bits
        {
            while(SPI_GetFlagStatus(SPI_FLAG_RXNE)!=SET);
            mode_add_MSB = SPI->DR;
            access = mode_add_MSB>>ACCESS_BIT; // Insulation of the access bit
            mode_add_MSB&=~(1<<ACCESS_BIT); // Ignorance of the access bit in the MSB address bits
            cpt++;
            SPI->DR=cpt; // debug
        }
        if(cpt==1) // Reception of the LSB address bits
        {
            while(SPI_GetFlagStatus(SPI_FLAG_RXNE)!=SET);
            add_LSB = SPI->DR;
            cpt++;
            add=((mode_add_MSB<<8)|add_LSB)&add_LSB; // Concatenation of the 15 bit register address
            if(access==READ_MODE)
            {
                temp = (uint8_t *) add;   // error line 249 : I would like to affect in temp the content of the memory case which address is add.
                SPI->DR=temp;
            }
        }
    }
}

Can anybody can help me please ? Let me know if it's not clear
Thank you
 
The interrupt code is not complete yet but I have yet a problem with the targetting of the register. I would like to send, from the master, the address of the IDR register for the port targetted and read it. I got the following error code with Cosmic
#error cpstm8 ..\..\src\stm8s_it.c:249(23+3) incompatible pointer assignment
    

Outcomes