This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS7961: ADS7961 SPI Manual mode receiving wrong/garbage frames.

Part Number: ADS7961

Hello, 

I have been trying to read values from the ADS7961 using STM32f07 using SPI but all I am getting is garbage values on the SPI Receive register of the Microcontroller.

it could be because I am packing the data wrongly while sending on the SPI.

I am trying to read the data from the 2nd channel for starters and thus sending 0x1100 i.e. manual mode and address of the second channel.

the yellow one is the clock and the blue one is the microcontroller output (MOSI) (the data capture is of the 3rd frame)

the response of the above frame is attached below 

the Yellow one being the clock and the blue one is the ADS output (MISO) (the data capture is of the 3rd frame)

as you can see the data received should contain the channel number i.e. 2 (according to the configuration sent) but it does not do as it supposed to do.

I believe the frame transmitted is correct and the code is also mentioned below. but I am missing out something.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void ManualModeTest()
{
	uint8_t channel = 2;
	uint8_t dataTx[2] = {0}, dataTxSend[2] = {0}, dataRx[2] = {0};
	uint16_t tempDataTx = TransPack(channel);
	memcpy(dataTx, &tempDataTx, sizeof(tempDataTx));
	fliparr(dataTx, dataTxSend, 2);
	ADS_TransmitReceiveFrame(dataTxSend, dataRx, 2, HAL_MAX_DELAY); //dataRx is the received data, 2 is the size, HAL_MAX_DELAY is the timeout
}

void fliparr(uint8_t *arr1, uint8_t *arr2, uint8_t size)
{
	for(int i = 0 ; i<size; i++)
	{
		arr2[(size-1) - i] = arr1[i];
	}
}

uint16_t TransPack(int channel) {
    uint8_t mode = 1;
    uint8_t gpioProg = 0;
    uint8_t Ref = 0;
    uint8_t power = 0;
    uint8_t GPIO = 0;
    uint8_t dioOut = 0;

    uint16_t transPack = mode;				//4 bits
    transPack = transPack << 1;
    transPack = transPack | gpioProg;		//1 bit
    transPack = transPack << 4;
    transPack = transPack | Ref;		       //4 bits
    transPack = transPack << 1;
    transPack = transPack | Ref ;		       //1 bit
    transPack = transPack << 1;
    transPack = transPack | power ;	              //1 bit
    transPack = transPack << 1;
    transPack = transPack | GPIO;	              //1 bit
    transPack = transPack << 4;
    transPack = transPack | dioOut;		      //4 bits

    return transPack;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

the SPI settings are as follows :

  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_ENABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 7;
  hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Any help would be really appreciable.

Thanks in advance.

Pranay

  • Hello,

    for this device, SDI data is latched at the rising edge of SCLK, which means that it needs to be stable at rising edges and change state at falling edge of SCLK.

    Currently, you have SDI changing state at rising edge of SCLK. This is likely leading to incorrect communications.

    Please change this and try again, the command you shared should correctly convert channel 2.

    Also note that the conversion result will not be seen until the second frame after the SDI command was given

    Regards

    Cynthia

  • Hello Cynthia, 

    You correct about the frame. It was SDI changing state at rising edge of SCLK which caused all the issues. Actually I was controlling the CS(Chip select) pin manually but forgot to tunn off the TI-Mode which got enabled in the STM32F07. Turning it off resolved all the issues.

    Thanks again for the quick reply.

    Regards

    Pranay