cancel
Showing results for 
Search instead for 
Did you mean: 

No Clock During Reads Using 1-Wire Spi and HAL 1.5.2

Keith Folske
Associate II
Posted on January 25, 2017 at 19:16

I am interfacing to an LIS2MDL Mag using 1-wire SPI bus mode.  The MCU is an STM32L4 and I am using ST's HAL peripheral library 1.5.2.

Reading from the Mag seems to be a problem.  I connected a scope to the CS, data and clock lines and found that there is no clock signal during the read phase of the transaction.  This can be seen in the two attached scope traces.  The green line (channel 2) is the clock.   The first trace is a zoomed-in view of the transaction.  The second view is a zoomed-out view showing that the clock is never toggled during the read phase.

As you can see, I write the WHO_AM_I register value out to the MAG using the HAL_SPI_Transmit() function.  I then call the HAL_SPI_RECEIVE() command with a count of 1 to read the response.  

My spi config is as follows:

   

hspi3

.

Instance

=

SPI3

;

   

hspi3

.

Init

.

Mode

=

SPI_MODE_MASTER

;

   

hspi3

.

Init

.

Direction

=

SPI_DIRECTION_1LINE

;

   

hspi3

.

Init

.

DataSize

=

SPI_DATASIZE_8BIT

;

   

hspi3

.

Init

.

CLKPolarity

=

SPI_POLARITY_LOW

;

   

hspi3

.

Init

.

CLKPhase

=

SPI_PHASE_1EDGE

;

   

hspi3

.

Init

.

NSS

=

SPI_NSS_SOFT

;

   

hspi3

.

Init

.

BaudRatePrescaler

=

SPI_BAUDRATEPRESCALER_8

;

   

hspi3

.

Init

.

FirstBit

=

SPI_FIRSTBIT_MSB

;

   

hspi3

.

Init

.

TIMode

=

SPI_TIMODE_DISABLE

;

   

hspi3

.

Init

.

CRCCalculation

=

SPI_CRCCALCULATION_DISABLE

;

   

hspi3

.

Init

.

CRCPolynomial

=

7

;

   

hspi3

.

Init

.

CRCLength

=

SPI_CRC_LENGTH_DATASIZE

;

   

hspi3

.

Init

.

NSSPMode

=

SPI_NSS_PULSE_DISABLE

;

   

if

(

HAL_SPI_Init

(

&

hspi3

)

!=

HAL_OK

)

   

{

       

Error_Handler

()

;

   

}

Am I using the HAL incorrectly for 1-wire configurations?  

Any help understanding how to enable the clock signal during the read phase of a 1-wire transaction would be greatly appreciated.

Thanks,

Keith

#lis2mdl #hal-driver #spi-spi_direction_1line_rx #l4
0 REPLIES 0