cancel
Showing results for 
Search instead for 
Did you mean: 

master full spi register with stm32l010c6t6

jdo
Associate II

Hi everyone! i am work with stm32l010c6t6 for comunicate llcc68 Lora module using spi, i find the standard peripheral library and not have, i don´t want use hal because i need maior control. i am using the example but this is using stm32f103c8t6 and need the configuration for stm32l010c6t6, i view the reference manual and the code example is:


uint8_t HALSpi1InOut(uint8_t data){
uint32_t retry=0;
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET){//¼ì²éÖ¸¶¨µÄSPI±ê־λÉèÖÃÓë·ñ:·¢ËÍ»º´æ¿Õ±ê־λ(»º³åÇø¿ÕÁ˾ͿÉÒÔ¿½±´Êý¾ÝÁË)
if((retry++)>2000){
//³¬Ê±ÁË
return 0xff;
}
}
SPI_I2S_SendData(SPI1, data); //ͨ¹ýÍâÉèSPIx·¢ËÍÒ»¸öÊý¾Ý
retry=0;

while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET){ //¼ì²éÖ¸¶¨µÄSPI±ê־λÉèÖÃÓë·ñ:½ÓÊÜ»º´æ·Ç¿Õ±ê־루·Ç¿ÕÁ˾ͱíʾ½ÓÊÕÊý¾ÝÍê³ÉÁË£©
if((retry++)>2000){
//³¬Ê±ÁË
return 0xff;
}
}
return SPI_I2S_ReceiveData(SPI1); //·µ»Øͨ¹ýSPIx×î½ü½ÓÊÕµÄÊý¾Ý
}

 

and i am make:

 

 
uint8_t HALSpi1InOut(uint8_t data){
if((SPI1->SR & SPI_SR_TXE) == SPI_SR_TXE) /* Test Tx empty */
{
/* Will inititiate 8-bit transmission if TXE */
*(uint8_t *)&(SPI1->DR) = data;
}
 
if((SPI1->SR & SPI_SR_RXNE) == SPI_SR_RXNE)
{
data = (uint8_t)SPI1->DR; /* receive data, clear flag */
 
}
 
return SPI1->DR;
 
}
0 REPLIES 0