cancel
Showing results for 
Search instead for 
Did you mean: 

Modify SPI register

david.ye
Associate II
Posted on November 27, 2017 at 12:55

Hello Everyone,

I am working on the STM8AL3166 and try modify the SPI register. 

My simple code is as below :

int main() {

   SPI_CR1 |= 0b00100100;      /* Configure as master and 500 kHz com speed

}

As read in the datasheet, I made a library.h with the correct address :

//STM8AL3166 SPI REGISTER

#define SPI_CR1 *(unsigned char*) 0x5200       //SPI Control Register 1   

But when I go in the debug session, the register does not change his value after executing the instruction

Is someone has encountered this problem? When I do the same for GPIO port A for instance, I have no problem.

May I am missing one configuration somewhere?

Please help.

Thank you for your time,

David

5 REPLIES 5
Vyacheslav Azarov
Associate III
Posted on November 27, 2017 at 13:25

Hello David, First verify the addresses with the datasheet. May errors in the header files also. And verify code generated by compiler.

Posted on November 28, 2017 at 03:32

Hello Vyacheslav,

Thank you for replying.

I double checked the address value and it is the correct one.

The header file is compiling without any errors and also, I know that the syntax is good because I can modify the GPIO register with my code.

What do you mean by 'verify code generated'? In the build log I have no warning and no errors if this is what you are looking for

In debugging session, I cannot freely modify the value of the registers except for the GPIO ones. When I change a value, the reset value is automatically set by the chip. Afterwards, it seems that I have this problem for every register of the uP. Is he in a blocked mode or something like that? For now I just want to modify a register..

Thank you for the help,

David

Posted on November 28, 2017 at 07:00

I meant not the absence of errors and warnings from the compiler. I mean the correctness of the binary instructions code. Everything should work but does not work. I repeatedly encountered errors in the headers and logic of compilers. Alas. However, I think that the reason is something else. Try another chip, or a debugger. Maybe something is malfunctioning.

Posted on November 29, 2017 at 12:40

Hello,

Apparently to modify the register, we have to enable the SPI by writing the corresponding bit in CLK_PCKENR1 at 1.

After that we can modify the registers of the SPI.

Thank again for you consideration,

Regards

Posted on December 08, 2017 at 19:45

Hello David, I was think it as for granted. And I did not take into account the possibility of such a mistake.