Problem with SPI using BitCloud 1.14 .

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everybody,

   I'm using a ATZB-900-B0 with Bitcloud 1.14.

I tried to write a small code that get from a ADS8344 (can 16 bits) data through SPI port.

It works good the data are correct.

The problem is that it is very slow...the system takes around 5 ms to perform a conversion

I have a general timer calling every 2 ms the function  readTempSPIData_0;

The acquisition is not complete beacause the system is always inside the function when the timer fired again !!!

What is wrong in my code?

 

//---- declaration of my SPi descriptor

  spiMode.tty       = SPI_CHANNEL_0,
  spiMode.clockMode = SPI_CLOCK_MODE0,
  spiMode.dataOrder = SPI_DATA_MSB_FIRST,
  spiMode.baudRate = SPI_CLOCK_RATE_2000,  
  spiMode.callback  = NULL;

 

//----- function called trough a general timer

void readTempSPIData_0(void)
{
  int i;     
  uint16_t res=0;
  uint8_t tmp2, tmp3, tmp4;   
 
  GPIO_0_clr();
    
  for (i=0;i<3;i++)
  {
      page_spi.buffer[i] = 0;    
  }
 

  HAL_WriteSpi(&spiMode,&cmd_can,1);

  HAL_ReadSpi(&spiMode,page_spi.buffer,3);
 
  GPIO_0_set();
  acquisitionBusy = false;
 
  tmp2 = page_spi.buffer[0];
  tmp3 = page_spi.buffer[1];
  tmp4 = page_spi.buffer[2];
  res = ((uint16_t)tmp2)<<9 | ((uint16_t)tmp3)<<1 | ((uint16_t)tmp4)>>7;

 
  jauge = res;
 
}

 

 

 

 

 

 

Last Edited: Fri. Oct 16, 2015 - 12:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Forget about BitCloud SPI driver and write your own. SPI peripheral is extremely simple.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for this answer Alex. Can you suggest one or more than one example source code that I can use for this kind of application.

 

Regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Example of a simple SPI driver can be found in LwMesh SDK, for example. But it is very easy and goes something like that:

Quote:

void spi_init(void)
{
  // TODO: Setup CS, MOSI, SCK pins as outputs and MISO as input

  SPCR = ((1 << SPE) | (1 << MSTR));
  SPSR = (1 << SPI2X);
}

 

uint8_t spi_write(uint8_t value)
{
  SPDR = value;
  while (!(SPSR & (1 << SPIF)));
  return SPDR;
}

 

That's all you need.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, thanks for your quick answer.

The code is now :

 

  uint8_t buffer[3];

 

  for (i=0;i<3;i++) {buffer[i] = 0;}    

  spi_init();
  GPIO_0_clr();
   

  spi_write(cmd_can);
  for (i=0;i<3;i++) {
        buffer[i] = spi_write(0);      
  }

 
  GPIO_0_set();
  acquisitionBusy = false;
 

Is it correct or not?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You only need to do spi_init() once and there is no need to initialize the array to 0, you will overwrite it later anyway. Otherwise it looks good.

 

Don't forget to initialize SPI pins.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks alex. It works good.

 

Regards Malek

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex,

   this is my final code :

void spi_init(void)
{
  // TODO: Setup CS, MOSI, SCK pins as outputs and MISO as input
  GPIO_USART0_RXD_make_in();
  GPIO_USART0_TXD_make_out();
  GPIO_USART0_EXTCLK_make_out();  
 
  UBRR0 = 0;
  UCSR0C = (1 << UMSEL01) | (1 << UMSEL00);
  UCSR0C |= ((0 << UDORD0)| ((1 << UCPOL0) | (1 << UCPHA0)));
  UCSR0B = (1 << RXEN0) | (1 << TXEN0);
  UBRR0 = SPI_CLOCK_RATE_2000;  
 
}

 

uint8_t spi_write(uint8_t value)
{
  // Send data
  UDR0 = value;    
  while (!(UCSR0A & (1 << RXC0)));    
  return UDR0;    
}

 

Every thing is ok but it seems that the problem is still here : the time to perfom a conversion is always around 5 ms.

Very strange...I will investigate !!!

 

Regards Malek