0

I am a beginner programmer of microcontrollers. My project uses stm8l051f3 and NSA2860X-QQNR chip. I am trying to get a value from one of the ADC inputs (TDATA) to the microcontroller. I use the SPI interface. It all works on the button. When I click on it, I send instructions so that the output from the chip allows me to get the values. Then, after a short delay, I poll the chip and try to get 3 bytes of ADC data. The problem is that I don't get an answer. I will add the microcontroller function code when pressing the button below, as well as the SPI configuration code. Also, I will add screenshots from the analyzer, which show how I send commands. I ask for help from knowledgeable specialists.

void read_EX_ADC16IN(void) {
  SPI1_CR1_bit.SPE = 1; // enable SPI1
  
  SPI1_CR2_BDOE = 1;      //BDOE: transmiting
  SPI_ENABLE();
  uint8_t instructionHeader[2] = {0xC0, 0x09};
  for(uint8_t i = 0; i < 2; i++) {
    SPI1_DR = instructionHeader[i];
    while (SPI1_SR_TXE != 1) {};
  }
  while (SPI1_SR_BSY != 0) {}
  
  SPI1_CR2_BDOE = 0;      //BDOE: receiving
  while (SPI1_SR_BSY != 0) {}
  while (SPI1_SR_RXNE != 1){};
  EX_ADCIN16[0] = SPI1_DR;
  while (SPI1_SR_RXNE != 1){};
  EX_ADCIN16[1] = SPI1_DR;
  while (SPI1_SR_RXNE != 1){};
  EX_ADCIN16[2] = SPI1_DR;
  usartTransmit(EX_ADCIN16, sizeof(EX_ADCIN16));
  
  SPI1_CR1_bit.SPE = 0; // disable SPI1
  SPI_DISABLE();

}

void SPI_Transfer(uint8_t* data, uint8_t sizeOfData)
{
  uint8_t dataToSend[3] = {0x00, 0x00, 0x80};
  SPI1_CR1_bit.SPE = 1; // enable SPI1
  SPI1_CR2_BDOE = 1;      //BDOE: transmiting
  SPI_ENABLE();
  for(uint8_t i = 0; i < 3; i++) {
    SPI1_DR = dataToSend[i];
    while (SPI1_SR_TXE != 1) {};
  }
  while (SPI1_SR_BSY != 0) {}
  SPI_DISABLE();
  SPI1_CR1_bit.SPE = 0; // disable SPI1
  
  for(uint32_t i = 0; i < 250; i++) {} //delay
}

void SPI_Config(void) {
  //----------------------------------------SPI 1
  CLK_PCKENR1_bit.PCKEN14 = 1;

  PB_DDR_bit.DDR4 = 1;   // NSS
  PB_DDR_bit.DDR5 = 1;   // SCK
  PB_DDR_bit.DDR6 = 1;   // MOSI 
  PB_DDR_bit.DDR7 = 0;   // MISO 

  PB_CR1_bit.C14 = 1;
  PB_ODR_ODR4 = 1;
  PB_CR1_bit.C15 = 1;
  PB_CR1_bit.C16 = 0;
  PB_CR1_bit.C17 = 0;

  PB_CR2_bit.C27 = 1;

  SPI1_CR1_bit.LSBFIRST = 0;
  SPI1_CR1_bit.CPOL = 0;
  SPI1_CR1_bit.CPHA = 0;
  SPI1_CR1_bit.MSTR = 1;
  
  SPI1_CR2_bit.SSM = 1;
  SPI1_CR2_bit.SSI = 1;
  SPI1_CR2_bit.BDOE = 1;
  SPI1_CR2_bit.BDM = 1; //

  SPI1_CR1_bit.BR = 0x05;
  
  SPI1_CR1_bit.SPE = 0;
}

My instruction

My request to NSA2860

At the moment, I was trying to set delays, start reading the conversion from the start of the program. None of this helped.

Issylin
  • 353
  • 2
  • 3
  • 11
KSGR
  • 1
  • 1
  • From what I see your SPI slave device is basically non-responsive at all? Are you sure NSA2860X-QQNR is connected / powered properly, and STM8 SPI speed is within working range? – Andrejs Cainikovs Jun 07 '23 at 09:13

0 Answers0