代码依赖于SPI中断。我希望主设备发送目标寄存器的地址(15位)和第16个(MSB),表示访问模式(读或写)。
我无法解决关于指针的问题。中断代码如下:
& sharpdefine ACCESS_BIT 7
& sharpdefine READ_INPUT_ID 0x50
char cpt,temp,add;
uint8_t mode_add_MSB,add_LSB;
布尔访问; //'1'= W,'0'= R.
INTERRUPT_HANDLER(SPI_IRQHandler,10)
{
if(SPI_GetITStatus(SPI_IT_RXNE)!= RESET)
{
if(cpt == 0)//访问模式位和7个MSB地址位的接收
{
而(SPI_GetFlagStatus(SPI_FLAG_RXNE)= SET!);
mode_add_MSB = SPI-> DR;
access = mode_add_MSB>> ACCESS_BIT; //访问位的绝缘
mode_add_MSB&安培; =〜(1 以下为原文
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 :
&sharpdefine ACCESS_BIT 7
&sharpdefine 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<
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
&sharperror cpstm8 ....srcstm8s_it.c:249(23+3) incompatible pointer assignment
#stm8-pointer-language-c-address