Can't read Cirrus CS5530 over SPI

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

NB Original thread title was "j'essai de faire une balance avec  CS5530 de Cirrus quelque soit les modifications appotées au code j'obtien toujours XFF comme resultat "

 

#include <SPI.h>
#include <Wire.h>
int CS = 10, SDI = 12, SDO = 11;    //slave select
void initialise_ADC()
{
  Serial.println("initialise_ADC");
  digitalWrite(CS, LOW);
  for (int i = 0; i < 15; i++)
  {
    SPI.transfer(0xFF);
  }
  SPI.transfer(0xFE);
  delay(0.000050);
  SPI.transfer(0x03);//commande pour écrire dans le registre de configuration
  SPI.transfer(0b00100000);//mise à 1 du bit RS
  SPI.transfer(0b00000000);
  SPI.transfer(0b00000000);
  SPI.transfer(0b00000000);
  delayMicroseconds(20);//attendre 20us
digitalWrite(CS, HIGH);
delayMicroseconds(0.000050);
digitalWrite(CS, LOW);
delayMicroseconds(0.000050);
  SPI.transfer(0x03);//commande pour écrire dans le registre de configuration
  SPI.transfer(0b00000000);//mise à 0 du bit RS
  SPI.transfer(0b00000000);
  SPI.transfer(0b00000000);
  SPI.transfer(0b00000000);
  digitalWrite(CS, HIGH);
  delayMicroseconds(0.000050);
digitalWrite(CS, LOW);
delayMicroseconds(0.000050);
  /*lecture du bit RV pour voir si une réinitialisation valide s'est produite (1)
    (la lecture du registre de configuration remet le bit RV à zéro)
  */
  byte RV1 = 0, RV2 = 0, RV3 = 0, RV4 = 0, validation = 0;
  SPI.transfer(0x0B);//commande pour lire dans le registre de configuration
  RV1 = SPI.transfer(0x00);
  RV2 = SPI.transfer(0x00);
  RV3 = SPI.transfer(0x00);
  RV4 = SPI.transfer(0x00);
 //  Serial.println("   RV 1234  ");
 digitalWrite(CS, LOW);
  delay(20);
  Serial.println(RV1, BIN);
  Serial.println(RV2, BIN);
  Serial.println(RV3, BIN);
  Serial.println(RV4, BIN);
  digitalWrite(CS, HIGH);
  
  //lecture du registre de gain
 byte g1=0,g2=0,g3=0,g4=0;
  digitalWrite(CS, LOW);
  delayMicroseconds(0.000050);
  SPI.transfer(0x02);
   g1 = SPI.transfer(0x00);
  g2 = SPI.transfer(0x00);
  g3 = SPI.transfer(0x00);
  g4 = SPI.transfer(0x00);
  digitalWrite(CS, HIGH);
  Serial.println("   g 1234  ");
  Serial.println(g1, BIN);
  Serial.println(g2, BIN);
  Serial.println(g3, BIN);
  Serial.println(g4, BIN);
  //lecture du registre d'offset
   byte of1=0,of2=0,of3=0,of4=0;
  digitalWrite(CS, LOW);
  delayMicroseconds(0.000050);
  SPI.transfer(0x01);
   of1 = SPI.transfer(0x00);
  of2 = SPI.transfer(0x00);
  of3 = SPI.transfer(0x00);
  of4 = SPI.transfer(0x00);
  digitalWrite(CS, HIGH);
  Serial.println("   of 1234  ");
  Serial.println(of1, BIN);
  Serial.println(of2, BIN);
  Serial.println(of3, BIN);
  Serial.println(of4, BIN);
  
delay(200);
}
void set_ADC()//parametrage de l'adc
{
  Serial.println("set_ADC");
  digitalWrite(CS, LOW);
  SPI.transfer(0x03); //commande pour écrire dans le registre de configuration
  SPI.transfer(0b00000000); //mise à 0 du bit RS
  SPI.transfer(0b00001000);
  SPI.transfer(0b01010100);
  SPI.transfer(0b00000000);
  digitalWrite(CS, HIGH);

  byte g1=0,g2=0,g3=0,g4=0;
  digitalWrite(CS, LOW);
  delayMicroseconds(0.000050);
  SPI.transfer(0x02);
   g1 = SPI.transfer(0x00);
  g2 = SPI.transfer(0x00);
  g3 = SPI.transfer(0x00);
  g4 = SPI.transfer(0x00);
  digitalWrite(CS, HIGH);
  Serial.println("  LECTURE REG CONFIG  ");
  Serial.println(g1, BIN);
  Serial.println(g2, BIN);
  Serial.println(g3, BIN);
  Serial.println(g4, BIN);
}

void setup()
{
  Serial.begin(9600);
  SPI.begin ();
  Serial.println("setup");
  parametrage = 0;

  pinMode(CS, OUTPUT);
  pinMode(SDO, OUTPUT);
  pinMode(SDI, INPUT);
  digitalWrite(CS, HIGH);//disable Slave Select

  SPI.begin ();//initialisation du bus SPI
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE1);
  SPI.setClockDivider(SPI_CLOCK_DIV8);   //divide the clock by 8 5MHz
  initialise_ADC();           //initialisation de l'ADC
  set_ADC();
  delay(100);
}

void loop()
{
  Serial.println("convert_data");
  convert_data();
}
void convert_data()
{
  Serial.println("convert_data");
  //acqisition des données
  byte data_avalaible1, data_avalaible2, data_avalaible3, data_avalaible4;
  digitalWrite(CS, LOW);
  delayMicroseconds(0.005);
  SPI.transfer(0b10000001);// mode de conversion continue
  //if(SDO==0)
  //{
  digitalWrite(CS, HIGH);
  Serial.print("données disponibles");
  digitalWrite(CS, LOW);
  SPI.transfer(0x00);
  for (int i = 0; i < 8; i++)
  {
    SDI = 1;
  }
  data_avalaible1 = SPI.transfer(0x00);
  data_avalaible2 = SPI.transfer(0x00);
  data_avalaible3 = SPI.transfer(0x00);
  data_avalaible4 = SPI.transfer(0x00);
  Serial.println(data_avalaible1,BIN);
  Serial.println(data_avalaible2,BIN);
  Serial.println(data_avalaible3,BIN);
  Serial.println(data_avalaible4,BIN);
  digitalWrite(CS, HIGH);
}
//}

Attachment(s): 

Last Edited: Tue. Jan 25, 2022 - 09:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Google translate says title is:

 

"If you want to get a balance with CS5530 of the circular quotes so that the modifications of the apps to the code J'obtien toujours XFF as a result "

 

I take it that means the SPI always return 0xFF

 

So presumably MISO is stuck high? Like so often with SPI it looks like a scope/analyser would be the best tool to investigate the problem. 

 

BTW does anyone know? Does the Arduino SPI stuff just wait indefinitely for SPIF or may it perhaps timeout (and have a signed int return) in which case what appears to be 0XFF may actually be -1 (0xFFFF)

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

BTW I just discovered the duplicate post so I locked that one. 

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

Google makes a bit of a mess translating the Thread Title:

I try to make a balance with CS5530 of circus whatever the modifications appoté to the code I always get XFF as result

I think I get the gist however.

 

At first sight I'm confused by this extract of code:

SPI.transfer(0x00);
for (int i = 0; i < 8; i++)
{
  SDI = 1;
}

Please explain what you are trying to achieve here.

 

 

PS: Kudos for attaching the datasheet.

Last Edited: Fri. Dec 31, 2021 - 05:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

First make a function where you pass all of your parameters (command &  4 bytes).....the function will do the CS control, writing, reading, delay,  etc to the chip

 

Calling this function when needed will make the code MUCH shorter & much easier to look for problems.

 

so all this :

digitalWrite(CS, LOW);
delayMicroseconds(0.000050);
  SPI.transfer(0x03);//commande pour écrire dans le registre de configuration
  SPI.transfer(0b00000000);//mise à 0 du bit RS
  SPI.transfer(0b00000000);
  SPI.transfer(0b00000000);
  SPI.transfer(0b00000000);
  digitalWrite(CS, HIGH);
  delayMicroseconds(0.000050);

 

would be simply:

write_TheChip(0x03, 0, 0, 0, 0) \\set config reg, all options are ...

Making the listing 9x shorter will be a big help to see what is going on!!

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Dec 31, 2021 - 06:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Google translate says title is:

 

"If you want to get a balance with CS5530 of the circular quotes so that the modifications of the apps to the code J'obtien toujours XFF as a result "

 

Lol, it doesn't help there is a typo in the title. It's "Cirrus" (the chipmaker) not circus...

The translation is, the OP wants to make a balance (weighting scale) and is using the CS5530 ADC from Cirrus. Whatever the changes made to the code, 0xFF is always read.

Last Edited: Fri. Dec 31, 2021 - 06:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  delayMicroseconds(0.000050);

the delayMicroseconds() function requires an integer argument.  The above will delay for 0 (well, as short as it can), which could be a problem if you were hoping for 50 us.

 

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

Bienvenue chez AVRFreaks!

 

 Dans le initialise_ADC(), cet code n'est pas terminée  
 
 digitalWrite(CS, LOW);
 delayMicroseconds(0.000050);
  /*lecture du bit RV pour voir si une réinitialisation valide s'est produite (1)
    (la lecture du registre de configuration remet le bit RV à zéro)
  */
  ......
 digitalWrite(CS, HIGH);
<-- MANQUE

 

Attention avec delays!

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

d'apres la fiche technique il faut envoyer plusieurs fois 1 à la broche SDO pour sortir du mode de conversion vontinu

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

merci pour le conseil je vais essayer

 

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

merci je viens de l'ajouter

digitalWrite(CS, HIGH);

 

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

malheuresement je ne dispose pas d'oscilloscope.quelque soit le code ou la connexion jai toujours comme resulta 0xFF

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

Well 0xFF for every transaction rather suggests that line called "SDI" from 5530 to Arduino is stuck "high" so it's never changing from 3.3/5.0V or whatever Vcc is.

 

Having said that, as I said in my first response this could be an "error code" (actually -1) not a real data value being returned IF the library implements a timeout so you need to check that possibility too. 

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


Malheuresement.

I think your SPI data lines are reversed. you must connect input to output and vice-versa.

 

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

int CS = 10, SDI = 12, SDO = 11;    //slave select

 

It looks like an Arduino Uno / Nano.  i.e. MOSI on digital #11, MISO on digital #12.

MOSI means Master-Out-Slave-In

 

The Uno is the Master.  CS5530 is the Slave.

So connect MOSI to SDI on the CS5530 and MISO to SDO on the CS5530.

 

Your code looks correct.   But my eyes glaze over when there are lots of repeated sequences.

Write a single function once.   Use many times.   Make your functions return a value.

 

void functions are the work of the Devil.

 

David 

Last Edited: Fri. Dec 31, 2021 - 10:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Eh, bien, non pas seulement ca.

 

voulez-vous installer MODE3- faites attention a SDO/Clk position la, Figure 7.

Peut etre qu'il vaut mieux que MODE1.

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

From the datasheet  timing diagrams in 2.2.3 Serial Port Interface it uses SPI Mode #0.

 

Very few devices use Mode 1 or 2.   Most use 0 or 3.

 

David.

 

 

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

On a master, MOSI is an output and it is an input on a slave. MOSI = Master Output Slave Input.

 

Likewise, on a master, MISO is an input and it is an output on a slave.

 

So, the schematic is correct in that area. The labels SDI and SDO are not good labels for SPI.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

SDI, SDO, SDA are perfectly appropriate names for a Slave.

 

A Mega AVR uses names like MOSI, MISO because they have the haywire-abilty feature.   The same SPI pin can flip from Master to Slave.

A Tiny AVR uses names like DI, DO because the pins are for a native Slave.   i.e. they never change input-output mode.

 

I have never seen SDI, SDO labels used on an AVR.

 

David.

 

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

aprés avoir modifier les connexions, j'obtien pa monent la valeur suivante dans le moniteur seri 

pour la sequance d'initialisation des trois registres 

Configuration Register,00000000

Gain Register   00000000

offset Register: 00000000

et d'autres fois lorsque je met le materiel en marche

Configuration Register,255

Gain Register   255

offset Register: 255

or la fiche tehnique dit que je devrais recevoir

Configuration Register:       00000000(H)

Offset Register:   00000000(H)

Gain Register      01000000(H)

 

 

 

 

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

</span></span></p>
<pre class=" c_cpp" data-pbcklang="c_cpp" data-pbcktabsize="4">
[code]
#include <SPI.h>
#include <Wire.h>
int CS = 10, SDI = 12, SDO = 11;    //slave select
const byte sync_1 = 0xFF, sync_0 = 0xFE;//synchronisation du port serie
const byte write_cfg = 0x03, read_cfg = 0x0B; //variable pour lire et ecrire dans le registre de configuration
const byte write_gain = 0x02 , read_gain = 0x0A ; //variable pour lire et ecrire dans le registre de gain
const byte write_offset = 0x01 , read_offset = 0x09; //variable pour lire et ecrire dans le registre d'offset
const byte mc_1=0xC0,mc_0=0x80;// perform continuous conversion mc_1 and single conversion mc_0
const byte _nul=0x00;//00000000
void sync_spi_adc(byte sync_1, byte sync_0)
{
  /////////synchronisation du port seri
  Serial.println("synchronisation du port seri");
  digitalWrite(CS, LOW);
  for (int i = 0; i < 15; i++)
  {
    SPI.transfer(sync_1);
  }
  SPI.transfer(sync_0);
  digitalWrite(CS, HIGH);
}

void write_reg_cfg(byte read_write, byte rs, byte nul_0, byte nul_1, byte nul_2)//lecture et ecriture du registre de configuration
{
byte cfg_1 = 0, cfg_2 = 0, cfg_3 = 0, cfg_4 = 0;
         if((read_write == 0x03)&(rs == 0x00)) { Serial.println("////CONFIG WRITE///////");} else { Serial.println("////CONFIG READ///////");}if (rs == 0x20) {//juste pour voir l'évolution du code
          Serial.println("////mise à 1 du bit RS ///////");} else if ((rs == 0x00) & (read_write == 0x03)) {  Serial.println("////mise à 0 du bit RS///////"); }
  
  /////////////////////////////////////
  digitalWrite(CS, LOW);
  SPI.transfer(read_write);//commande pour écrire/ecrite dans le registre de configuration
  cfg_1 = SPI.transfer(rs); //mise à 1/0 du bit RS
  cfg_2 = SPI.transfer(nul_0);
  cfg_3 = SPI.transfer(nul_1);
  cfg_4 = SPI.transfer(nul_2);
  digitalWrite(CS, HIGH);

  delay(20);
  Serial.println(cfg_1, BIN); //affichage dans le moniteur serie des valeus du registre de configuration
  Serial.println(cfg_2, BIN);
  Serial.println(cfg_3, BIN);
  Serial.println(cfg_4, BIN);
}


void write_reg_gain(byte read_write, byte nul_0, byte nul_1, byte nul_2, byte nul_3)//lecture et ecriture du registre de gain
{
  Serial.println("//// READ GAIN///////");
  byte gain_1 = 0, gain_2 = 0, gain_3 = 0, gain_4 = 0;
  /////////////////////////////////////
  digitalWrite(CS, LOW);
  SPI.transfer(read_write);//commande pour écrire/ecrite dans le registre de gain
  gain_1 = SPI.transfer(nul_0); //mise à 1/0 du bit RS
  gain_2 = SPI.transfer(nul_1);
  gain_3 = SPI.transfer(nul_2);
  gain_4 = SPI.transfer(nul_3);
  digitalWrite(CS, HIGH);

  Serial.println(gain_1, BIN); //affichage dans le moniteur serie des valeus du registre de gain
  Serial.println(gain_2, BIN);
  Serial.println(gain_3, BIN);
  Serial.println(gain_4, BIN);

}

void write_reg_offset(byte read_write, byte nul_0, byte nul_1, byte nul_2, byte nul_3)//lecture et ecriture du registre de offset
{
  Serial.println("////READ OFFSET///////");
  byte offset_1 = 0, offset_2 = 0, offset_3 = 0, offset_4 = 0;
  /////////////////////////////////////
  digitalWrite(CS, LOW);
  SPI.transfer(read_write);//commande pour écrire/ecrite dans le registre de offset
  offset_1 = SPI.transfer(nul_0); //mise à 1/0 du bit RS
  offset_2 = SPI.transfer(nul_1);
  offset_3 = SPI.transfer(nul_2);
  offset_4 = SPI.transfer(nul_3);
  digitalWrite(CS, HIGH);

  Serial.println(offset_1, BIN); //affichage dans le moniteur serie des valeus du registre de offset
  Serial.println(offset_2, BIN);
  Serial.println(offset_3, BIN);
  Serial.println(offset_4, BIN);

}
void setup()
{
  Serial.begin(9600);
  SPI.begin ();
  Serial.println("setup");
  pinMode(CS, OUTPUT);
  pinMode(SDO, OUTPUT);
  pinMode(SDI, INPUT);
  digitalWrite(CS, HIGH);//disable Slave Select

  SPI.begin ();//initialisation du bus SPI
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE1);
  SPI.setClockDivider(SPI_CLOCK_DIV8);   //divide the clock by 8 5MHz
  //////////////INITIALISATION DE L'ADC
  Serial.println("//// BEGIN INITIALISATION///////");
  delay(500);
  sync_spi_adc(sync_1, sync_0); //synchronisation du port spi de l'ADC
  write_reg_cfg(write_cfg, 0x20, 0x00, 0x00, 0x00); //initialisation de l'ADC mise à 1 de rs
  write_reg_cfg(write_cfg , 0x00, 0x00, 0x00, 0x00); //initialisation de l'ADC mise à 0 de rs
  /////////////////////////////
  /*lecture des registres de:CONFIGURATION;OFFSET;GAIN
    pour voir si une initialisation valide s'est produite
  */
  write_reg_cfg(read_cfg , 0x00, 0x00, 0x00, 0x00); //lecture du registre de configuration
  write_reg_gain(read_gain , 0x00, 0x00, 0x00, 0x00); //lecture du registre de GAIN
  write_reg_offset(read_offset , 0x00, 0x00, 0x00, 0x00); //lecture du registre de OFFSET

  write_reg_cfg(write_cfg , 0x00, 0x08, 0x54, 0x00); //parametrage du registre de configuration
  write_reg_cfg(read_cfg , 0x00, 0x00, 0x00, 0x00); //lecture du registre de configuration


  Serial.println("////END OF INITIALISATION///////");
  delay(100);
}

void loop()
{
  Serial.println("convert_data");
  convert_data(mc_1);
}
void convert_data(byte mc)
{
  Serial.println("////CONVERT CONTINUOUS DATA///////");
  byte data_1 = 0, data_2 = 0, data_3 = 0, data_4 = 0;
  /////////////////////////////////////
  digitalWrite(CS, LOW);
  SPI.transfer(mc);//commande pour lire les données de conversion
  //;
  if(SDO==0)//données disponible
  {
    Serial.println("données disponible");
  }
           SPI.transfer(_nul);//maintien du mode continu pandant les 8 premiers SCK
  data_1 = SPI.transfer(_nul);
  data_2 = SPI.transfer(_nul);
  data_3 = SPI.transfer(_nul);
  data_4 = SPI.transfer(_nul);
  digitalWrite(CS, HIGH);

  Serial.println(data_1, DEC); //affichage dans le moniteur serie des valeus du registre de offset
  Serial.println(data_2, DEC);
  Serial.println(data_3, DEC);
  Serial.println(data_4, DEC);

}

bonsoir et bonne anée à tous aprés vos remarques j'ai ameliorer le code . j'ai laissé la partie étalonnage car aprés une  initialisation valide, l'ADC est en mesure d'effectuer des conversions d'aprés la fiche technique.malheuresement j'ai toujours le meme message "0XFF" dans le moniteur seri

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

Toujours MODE1- n'avez vous fait MODE3?

 

Une bonne anée à vous! Nous allons a 2022, pouvez-vous parler Anglais, svp!

Il est bien de commencer un peu, et maintenant.

Avec Anglais on pouvais vous ajouter bien davantage.

C'est important a cet Forum- une des regles.

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

Merci pour votre assistance, Milan

Ross McKenzie, Melbourne Australia

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

Write a function with the parameters you need to send, then it will be far more efficient & much easier to  determine the issues 

Control of CS should ONLY appear in the function

 

  digitalWrite(CS, LOW);
  SPI.transfer(read_write);//commande pour écrire/ecrite dans le registre de configuration
  cfg_1 = SPI.transfer(rs); //mise à 1/0 du bit RS
  cfg_2 = SPI.transfer(nul_0);
  cfg_3 = SPI.transfer(nul_1);
  cfg_4 = SPI.transfer(nul_2);
  digitalWrite(CS, HIGH);

should look like

      good_job = my_write(read_write, rs, nul_0, nul_1, nul_2);

 

The first parameter specifies which chip register will be written, followed by 32 bits of information (4 more bytes)   ...5 bytes total will be sent to the chip each time

 

cs control belongs inside the function, not repeated all over the place!!!  That is why you are making a function.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sat. Jan 1, 2022 - 01:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I WILL MAKE AN EFFORT TO SPEAK ENGLISH

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

You do not need to make any effort.   Type your message into your private Editor in French.

 

Then use Google Translate to post the English message on the Forum.

 

There are many non-English speakers on this Forum.   It is better to translate a "good" French message than to attempt to write a message in "poor" English.

 

Follow the advice in #24.   It will make your code easier to write and easier to read.   And easier to fix any problems !!

 

David.

 

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

Good to you. Let discuss the code: 

void loop()
{
  Serial.println("convert_data");
  convert_data(mc_1);
}

You should slow down access to chip- needs to be 8Hz or less. One delay of 150ms will do it, if there are no other delays.

 

Now, the question- how you started this all. Is there any template for the code, if so can we see it.

 

 

 

  

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

david.prentice wrote:
Type your message into your private Editor in French.

 

Then use Google Translate to post the English message on the Forum.

I'm not sure that's such a good idea? 

 

It means we only get to see google's (mis)interpretation - not the original.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does that matter? If we see non-English text here surely the thing anyone looking is likely to do is feed it into Google Translate anyway. Let's face it Google have basically "won" the translation battle just as they have won the search battle and so many other things (Android dominant phone OS, YouTube dominant video storage service etc etc) 

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

awneil wrote:

I'm not sure that's such a good idea? 

 

It means we only get to see google's (mis)interpretation - not the original.

 

Agreed. Why force the OP to do what anyone can do, and lose the original information? Several people here can understand French (I can read it at least).

 

edit: maybe the OP can post both the French original, and google's translation. Code comments are in French too, though. That can't (easily) be fed into google.

 

Last Edited: Sun. Jan 2, 2022 - 12:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bonjour à tous merci pour tous vos précieux conseils. après quelques jours de galère sur mon modèle j'ai enfin réussi à communiquer avec la bête. J'arrive à lire les données faire le reset; la synchronisation et même l'étalonnage. les calibrages (offset et gain) que j'ai fait jusqu'à présent ne me permettent pas d'avoir des valeurs fixes en sortie.aidez moi.....

#include <SPI.h>
#include <Wire.h>
int CS = 10, SDI = 12, SDO = 11; //slave select
const byte sync_1 = 0xFF, sync_0 = 0xFE;//serial port synchronization
const byte write_cfg = 0x03, read_cfg = 0x0B; //variable to read and write to the configuration register
const byte write_gain = 0x02 , read_gain = 0x0A ; //variable to read and write to gain register
const byte write_offset = 0x01 , read_offset = 0x09; //variable to read and write in the offset register
const byte mc_1 = 0xC0, mc_0 = 0x80, cal_gain = 0x86, cal_offset = 0x85 ; // perform continuous conversion mc_1 and single conversion mc_0
const byte _nul = 0x00; //00000000
bool Begin = 0, End = 1;
///////////////////////////////////////////////////

int BP_UP = 2, BP_DOWN = 3, BP_LEFT = 4, BP_RIGHT = 5, BP_ESC = 6 , BP_OK = 7; //variable navigation push buttons: direction, validation, powerconst int BP_SET = 8;  //bouton poussoir set_up
int etat1, etat2, etat3, etat4, etat5, etat6;
unsigned long time_set;
unsigned long tempo_mode_reglage = 3000, time_to_move, prev_micro, millis();
bool parametrage;

/////////////////////////////////////////////////////////////////////////////////////////
void cs5530(bool start)
{
  if (start == 0)
  {
    digitalWrite(CS, LOW);
  }
  else
  {
    digitalWrite(CS, HIGH);
  }

}
void sync_spi_adc(byte sync_1, byte sync_0)
{
  /////////serial port synchronization
  Serial.println("serial port synchronization");
  //cs5530(Begin);
  for (int i = 0; i < 15; i++)
  {
    SPI.transfer(sync_1);
  }
  SPI.transfer(sync_0);


}

void write_reg_cfg(byte read_write, byte rs, byte nul_0, byte nul_1, byte nul_2)//lecture et ecriture du registre de configuration
{
  byte cfg_1 = 0x0, cfg_2 = 0x0, cfg_3 = 0x0, cfg_4 = 0x0, cfg_5 = 0x0, cfg_6 = 0x0, cfg_7 = 0x0, cfg_8 = 0x0;

  /////////////////////////////////////
  if (rs == 0x20) // if , set the configuration register
  {
    SPI.transfer(read_write);//ommand to write/writes in the configuration register
    cfg_1 = SPI.transfer(rs); //set RS bit to 1
    cfg_2 = SPI.transfer(nul_0);
    cfg_3 = SPI.transfer(nul_1);
    cfg_4 = SPI.transfer(nul_2);

    delayMicroseconds(4);//Wait 4 micro seconds

    SPI.transfer(read_write);
    cfg_5 = SPI.transfer(_nul); //SET RS BIT TO 0
    cfg_6 = SPI.transfer(nul_0);
    cfg_7 = SPI.transfer(nul_1);
    cfg_8 = SPI.transfer(nul_2);

    delay(300);
    Serial.println("set bit rs to 1");
    Serial.println(cfg_1, BIN); //display in the serial monitor of the values ​​of the configuration register    Serial.println(cfg_2, BIN);
    Serial.println(cfg_3, BIN);
    Serial.println(cfg_4, BIN);
    Serial.println("set bit rs to 0");
    Serial.println(cfg_5, BIN); //display in the serial monitor of the values ​​of the configuration register    Serial.println(cfg_6, BIN);
    Serial.println(cfg_7, BIN);
    Serial.println(cfg_8, BIN);
    //
  }
  else //if not, set the configuration register
  {
    SPI.transfer(read_write);//ommand to write/writes in the configuration register
    cfg_1 = SPI.transfer(rs);
    cfg_2 = SPI.transfer(nul_0);
    cfg_3 = SPI.transfer(nul_1);
    cfg_4 = SPI.transfer(nul_2);
    delay(300);
    Serial.println("////READ CONFIG///////");
    Serial.println(cfg_1, BIN);   Serial.println(cfg_2, BIN);
    Serial.println(cfg_3, BIN);
    Serial.println(cfg_4, BIN);
  }
}


void write_reg_gain(byte read_write, byte nul_0, byte nul_1, byte nul_2, byte nul_3)//lecture et ecriture du registre de gain
{
  Serial.println("//// READ GAIN///////");
  byte gain[3] ;
 float resultat[3];
  /////////////////////////////////////
  //cs5530(Begin);
  SPI.transfer(read_write);//
  gain[0] = SPI.transfer(nul_0);
  gain[1] = SPI.transfer(nul_1);
  gain[2] = SPI.transfer(nul_2);
  gain[3] = SPI.transfer(nul_3);
  delay(300);

  Serial.println(gain[0], BIN); Serial.println(gain[1], BIN);
  Serial.println(gain[2], BIN);
  Serial.println(gain[3], BIN);

  resultat[0] = gain_b_d(gain[0],0);
  resultat[1] = gain_b_d(gain[1],1);
  resultat[2] = gain_b_d(gain[2],2);
  resultat[3] = gain_b_d(gain[3],3);


   Serial.println("gain en decimal");  Serial.println(resultat[0],6);
  Serial.println(resultat[1],6);
  Serial.println(resultat[2],6);
  Serial.println(resultat[3],6);
  
Serial.println((resultat[0] + resultat[1] + resultat[2]+resultat[3]),6);
  delay(500);
}

void write_reg_offset(byte read_write, byte nul_0, byte nul_1, byte nul_2, byte nul_3)//lecture et ecriture du registre de offset
{
  Serial.println("////READ OFFSET///////");
  byte offset_1 = 0, offset_2 = 0, offset_3 = 0, offset_4 = 0;
  SPI.transfer(read_write);
  offset_1 = SPI.transfer(nul_0);
  offset_2 = SPI.transfer(nul_1);
  offset_3 = SPI.transfer(nul_2);
  offset_4 = SPI.transfer(nul_3);

  delay(300);

  Serial.println(offset_1, BIN);
  Serial.println(offset_2, BIN);
  Serial.println(offset_3, BIN);
  Serial.println(offset_4, BIN);

}
void setup()
{

  Serial.begin(9600);
  SPI.begin ();
  Serial.println("setup");
  pinMode(CS, OUTPUT);
  pinMode(SDO, OUTPUT);
  pinMode(SDI, INPUT);
  digitalWrite(CS, HIGH);//disable Slave Select
  SPI.begin ();//initialisation du bus SPI
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV8);   //divide the clock by 8 5MHz
  //////////////INITIALISATION DE L'ADC
  Serial.println("//// BEGIN INITIALISATION///////");
  //
  cs5530(Begin);
  sync_spi_adc(sync_1, sync_0); 
  Serial.println("///////// reset  //////// ");
  write_reg_cfg(write_cfg, 0x20, _nul, _nul, _nul); //reset du cs5530
 
  write_reg_cfg(read_cfg , _nul, _nul, _nul, _nul); //read config register
  write_reg_gain(read_gain , _nul, _nul, _nul, _nul); //read GAIN register
  write_reg_offset(read_offset , _nul, _nul, _nul, _nul); //read offset register OFFSET
  /////////////////ecriture de 35(D) dans le registre de gin

 

  //SPI.transfer(cal_offset);
  //write_reg_offset(read_offset , _nul, _nul, _nul, _nul); 
 // write_reg_gain(read_gain , _nul, _nul, _nul, _nul); //
  ////////////////////////////////////////////////////////////////
  //write_reg_cfg(write_cfg , _nul, 0x08, 0x54, _nul); //configuration register setting
  write_reg_cfg(write_cfg , 0x80,0x0, 0x04, _nul); //configuration register setting
  write_reg_cfg(read_cfg , _nul, _nul, _nul, _nul); //read configuration register

  cs5530(End);

  Serial.println("////END OF INITIALISATION///////");
  delay(300);
}


void loop()
{ cs5530(Begin);
  /////////////////////////////////////
  long time_to_move;
  etat5 = digitalRead(BP_OK), etat1 = digitalRead(BP_UP), etat2 = digitalRead(BP_DOWN), etat3 = digitalRead(BP_LEFT), etat4 = digitalRead(BP_RIGHT);
  etat6 = digitalRead(BP_ESC);
  parametrage = 0;
  if (etat3 == 0 || (etat4 == 0) )
  {
    ///////conversion/////////////////
    //Serial.println("convert_data");
    // prev_micro = micros();
    convert_data(mc_0);
    time_set = millis();
    //  Serial.print("time_set "), Serial.print(time_set), Serial.print("  millis()  "), Serial.println(millis());
  }
  if ((etat3 == 1) && (etat4 == 1))
  {
    if (((millis() - ( time_set)) >= tempo_mode_reglage))
    { Serial.print("calibration  "), Serial.print(parametrage), Serial.print("  time_set  "), Serial.print(time_set); Serial.print("  millis()  "), Serial.println(millis());
      parametrage = 1;
      while ( parametrage == 1)
      {
        etat6 = digitalRead(BP_ESC);
        // code de parametres
        calibration();
        Serial.println(" end of callibration ");
        delay(500);
        /*  if (etat6 == 1)
          {
            parametrage = 0 ;*/
        break;
        // }
        //delay(500);

      }

    }
  }
}
void convert_data(byte mc_0)
{


  //sync_spi_adc(sync_1, sync_0);
  //Serial.println("////CONVERT single DATA///////");
  byte data_1 = 0, data_2 = 0, data_3 = 0, data_4 = 0, flag = 0, sdi = 0;
  int rx = digitalRead(SDI);
  /////////////////////////////////////

  
  byte data[3];
  long resultat[2]; float poids;
  float  result,y;
  prev_micro = micros();
  //Serial.print("1_prev_micro= ");  Serial.println(micros()-prev_micro);
  //

  SPI.transfer(mc_0);
  do
  {

  }
  while ((micros() - prev_micro) <= 59000);
  Serial.print("2_prev_micro= ");  Serial.println(micros() - prev_micro);
  flag = SPI.transfer(_nul);
  data[0] = SPI.transfer(_nul);
  data[1] = SPI.transfer(_nul);
  data[2] = SPI.transfer(_nul);
  data[3] = SPI.transfer(_nul);
  //   }

  Serial.print("flag== "); Serial.println(flag, DEC);

  Serial.println(data[0], BIN); 
  Serial.println(data[1], BIN);
  Serial.println(data[2], BIN);
  Serial.println(data[3], BIN);

  resultat[0] = convert_b_d(data[0], 0);
  resultat[1] = convert_b_d(data[1], 1);
  resultat[2] = convert_b_d(data[2], 2);
  //resultat[3] = convert_b_d(data[3], 3);
  Serial.print("resultat == ");
  Serial.println(resultat[0]);
  Serial.println(resultat[1]);
  Serial.println(resultat[2]);
 
  Serial.print(" B to D ==");
  //  long poids;
  result = resultat[0] + resultat[1] + resultat[2];
  Serial.println(result);
  Serial.print(" entrée= ");
 long val,masse;int p_max=60000,etallon=5000;
  
 Serial.print((result *5 / (pow(2, 24))), 4); Serial.println(" v ");
/*masse=
 y16760831.00=x5000
 x          = y      */
 y=5000*result/16760831;
Serial.print(y,4);Serial.println(" kg ");
  write_reg_offset(read_offset , _nul, _nul, _nul, _nul);
  write_reg_gain(read_gain , _nul, _nul, _nul, _nul);
  //  delay(200);
  // i++;
  prev_micro = micros();
 
}

long convert_b_d(byte data, int n)
{
  if (n == 0)
  {
    return  ((((data & 0b10000000) >> 7) * pow(2, 23)) + (((data & 0b01000000) >> 6) * pow(2, 22)) + (((data & 0b00100000) >> 5) * pow(2, 21))
             + (((data & 0b00010000) >> 4) * pow(2, 20)) + (((data & 0b00001000) >> 3) * pow(2, 19)) + (((data & 0b00000100) >> 2) * pow(2, 18))
             + (((data & 0b00000010) >> 1) * pow(2, 17)) + (((data & 0b00000001) >> 0) * pow(2, 16)));

  }
  if (n == 1)
  {
    return (((data >> 7) * pow(2, 15)) + (((data & 0b01000000) >> 14) * pow(2, 14)) + (((data & 0b00100000) >> 5) * pow(2, 13))
            + (((data & 0b00010000) >> 4) * pow(2, 12)) + (((data & 0b00001000) >> 3) * pow(2, 11)) + (((data & 0b00000100) >> 2) * pow(2, 10))
            + (((data & 0b00000010) >> 1) * pow(2, 9))  + (((data & 0b00000001) >> 0) * pow(2, 8)));
  }
  if (n == 2)
  {
    return (((data >> 7) * pow(2, 7)) + (((data & 0b01000000) >> 6) * pow(2, 6)) + (((data & 0b00100000) >> 5) * pow(2, 5))
            + (((data & 0b00010000) >> 4) * pow(2, 4)) + (((data & 0b00001000) >> 3) * pow(2, 3)) + (((data & 0b00000100) >> 2) * pow(2, 2))
            + (((data & 0b00000010) >> 1) * pow(2, 1)) + (((data & 0b00000001) >> 0) * pow(2, 0)));
  }
  /*if (n == 3)
    {
    return (((data >> 7) * pow(2, 23)) + (((data & 0b01000000) >> 6) * pow(2, 22)) + (((data & 0b00100000) >> 5) * pow(2, 21))
            + (((data & 0b00010000) >> 4) * pow(2, 20)) + (((data & 0b00001000) >> 3) * pow(2, 19)) + (((data & 0b00000100) >> 2) * pow(2, 18))
            + (((data & 0b00000010) >> 1) * pow(2, 17)) + (((data & 0b00000001) >> 0) * pow(2, 16)));
    }*/

}



float gain_b_d(byte data, int n)
{
 if (n == 0)
    {
    return (((data >> 7) * pow(2, 7)) + (((data & 0b01000000) >> 6) * pow(2, 6)) + (((data & 0b00100000) >> 5) * pow(2, 5))
            + (((data & 0b00010000) >> 4) * pow(2, 4)) + (((data & 0b00001000) >> 3) * pow(2, 3)) + (((data & 0b00000100) >> 2) * pow(2, 2))
            + (((data & 0b00000010) >> 1) * pow(2, 1)) + (((data & 0b00000001) >> 0) * pow(2, 0)));
    }
  
  if (n == 1)
  {
    return (((data >> 7) * pow(2, -1)) + (((data & 0b01000000) >> 6) * pow(2, -2)) + (((data & 0b00100000) >> 5) * pow(2, -3))
            + (((data & 0b00010000) >> 4) * pow(2, -4)) + (((data & 0b00001000) >> 3) * pow(2, -5)) + (((data & 0b00000100) >> 2) * pow(2, -6))
            + (((data & 0b00000010) >> 1) * pow(2, -7)) + (((data & 0b00000001) >> 0) * pow(2, -8)));
  }
  
  if (n == 2)
  {
    return (((data >> 7) * pow(2, -9)) + (((data & 0b01000000) >> 14) * pow(2,-10)) + (((data & 0b00100000) >> 5) * pow(2, -11))
            + (((data & 0b00010000) >> 4) * pow(2, -12)) + (((data & 0b00001000) >> 3) * pow(2, -13)) + (((data & 0b00000100) >> 2) * pow(2, -14))
            + (((data & 0b00000010) >> 1) * pow(2, -15))  + (((data & 0b00000001) >> 0) * pow(2, -16)));
  }
  
  if (n == 3)
  {
    return  ((((data & 0b10000000) >> 7) * pow(2, -17)) + (((data & 0b01000000) >> 6) * pow(2, -18)) + (((data & 0b00100000) >> 5) * pow(2, -19))
             + (((data & 0b00010000) >> 4) * pow(2, -20)) + (((data & 0b00001000) >> 3) * pow(2, -21)) + (((data & 0b00000100) >> 2) * pow(2, -22))
             + (((data & 0b00000010) >> 1) * pow(2, -23)) + (((data & 0b00000001) >> 0) * pow(2, -24)));

  }
  /**/

}
void calibration()
{

  Serial.println("callibration");
  delay(200);
  Serial.println("callibration offset");
  Serial.println("empty the platform");
  delay(5000);
  SPI.transfer(cal_offset);

  delay(4000);
  write_reg_offset(read_offset , _nul, _nul, _nul, _nul); //read the OFFSET regiister
  delay(4000);
  Serial.println(" posez une masse ");
  Serial.println("callibration gain");
  delay(6000);
  SPI.transfer(cal_gain);
  //write_reg_gain(write_gain , 0x02, _nul, _nul, _nul);
  delay(4000);



}

 

Last Edited: Mon. Jan 24, 2022 - 04:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

serial monitor 

Attachment(s): 

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

Soyez bienvenue.

By des valeurs fixes you mean 'values repeatable'?

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

say there is too much variation

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

Something seems just plain wrong..to do something simpple, the code seems a mile long

 

For example, right off the bat (write_reg_cfg) you see

    SPI.transfer(read_write);//ommand to write/writes in the configuration register
    cfg_1 = SPI.transfer(rs); //set RS bit to 1
    cfg_2 = SPI.transfer(nul_0);
    cfg_3 = SPI.transfer(nul_1);
    cfg_4 = SPI.transfer(nul_2);

why is this repeated twice:??? It is only needed once, at the beginning of the function

 

I made a stab at condensing it--I believe this will essentially give a similar result with a substantially shorter amount of things to look at:

void write_reg_cfg(byte read_write, byte rs, byte nul_0, byte nul_1, byte nul_2)//lecture et ecriture du registre de configuration
{
    byte cfg_1 = 0x0, cfg_2 = 0x0, cfg_3 = 0x0, cfg_4 = 0x0, cfg_5 = 0x0, cfg_6 = 0x0, cfg_7 = 0x0, cfg_8 = 0x0;

    SPI.transfer(read_write);//ommand to write/writes in the configuration register
    cfg_1 = SPI.transfer(rs);
    cfg_2 = SPI.transfer(nul_0);
    cfg_3 = SPI.transfer(nul_1);
    cfg_4 = SPI.transfer(nul_2);
    Serial.println("////READ CONFIG///////");
    Serial.println(cfg_1, BIN);
    Serial.println(cfg_2, BIN);
    Serial.println(cfg_3, BIN);
    Serial.println(cfg_4, BIN);

  if (rs == 0x20) // if , set the configuration register
  {
    delayMicroseconds(4);//Wait 4 micro seconds
    SPI.transfer(read_write);
    cfg_5 = SPI.transfer(_nul); //SET RS BIT TO 0
    cfg_6 = SPI.transfer(nul_0);
    cfg_7 = SPI.transfer(nul_1);
    cfg_8 = SPI.transfer(nul_2);
    delay(300);
    Serial.println("set bit rs to 0");
    Serial.println(cfg_5, BIN); //display in the serial monitor of the values ​​of the configuration register
    Serial.println(cfg_6, BIN);
    Serial.println(cfg_7, BIN);
    Serial.println(cfg_8, BIN);
  }
}

All of these multiple lines of print statements should probably also be combined into one or two formatted print statements, why have 15 lines of print statements?

The entire function could probable be whittled down further to 15 lines of code....keep at it!

 

float gain_b_d

This twisted calculation seems to border on unplanned nonsense---surely it can be unraveled into something manageable and straightforward??

 

Do similar improvements to the rest of the code, it can but cut by at least half or more. Then you only have half the places to look for troubles.

There is absolutely no way you should need 90 different print statements, or even close to that--maybe a dozen will be plenty??

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Jan 25, 2022 - 12:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Golly!   Those are some short delays that you have in the ADC_init section:

 

    delayMicroseconds(0.000050);

 

That's about the amount of time that it takes for light to travel about 1/10 of a millimeter!

I'm not sure that your AVR has that kind of precision, but some of the later devices might.

Consult the data sheet.

 

 

*****************************

Golly! Voici quelques courts retards que vous avez dans la section ADC_init :      delayMicroseconds(0.000050);

 

C'est à peu près le temps qu'il faut à la lumière pour voyager environ 1/10 de millimètre!

Je ne suis pas sûr que votre AVR ait ce genre de précision, mais certains des derniers appareils le pourraient. Consultez la fiche technique.

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

Simonetta wrote:

Golly!   Those are some short delays that you have in the ADC_init section:

 

    delayMicroseconds(0.000050);

 

That's about the amount of time that it takes for light to travel about 1/10 of a millimeter!

I'm not sure that your AVR has that kind of precision, but some of the later devices might.

Consult the data sheet.

 

You forgot the /sarc tag... there is no AVR that runs at 1/0.00005 MHz (20 GHz), in fact IDK if there is any cpu capable of such speeds...

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

I also noticed that one of the SPI transfers in the ADC_init section has a CS-go-low without a corresponding CS-go-high.  The transfer that has { SPI.transfer(0x0B);  }.

 

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

I am gobsmacked.

    return  ((((data & 0b10000000) >> 7) * pow(2, 23)) + (((data & 0b01000000) >> 6) * pow(2, 22)) + (((data & 0b00100000) >> 5) * pow(2, 21))              + (((data & 0b00010000) >> 4) * pow(2, 20)) + (((data & 0b00001000) >> 3) * pow(2, 19)) + (((data & 0b00000100) >> 2) * pow(2, 18))              + (((data & 0b00000010) >> 1) * pow(2, 17)) + (((data & 0b00000001) >> 0) * pow(2, 16))); 

when you could just say return (data << 16);

 

Sit down with a nice cup of tea.   Tidy up your program.   Reduce the duplicated sequences e.g. with a function that takes arguments.   Ask if you are unsure of something.

 

You will find code easier to write and maintain when it is in short functions that you can view on your PC screen.    (or print on paper)

 

David.

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

 

thank you for the remark the code has improved since december 31 look earlier at the one of january 24
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
to be able to do the calculations on the values ​​sampled by the cs5530 you have to do a 24-bit binary conversion to decimal. I haven't found a better way to do it.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Seriously.   Simplify your code.   It will make your life much easier.

 

Personally,  I would print the existing code on paper.   Then go away from the PC.   Sit down with a pencil.   Identify which sequences are "repeated".  Which calculations are "very complex".   Which statements look unusual  ...

 

It is very satisfying to draw lines through long sequences.   Reduce to a single function with arguments.

Use a pencil.  Not a pen.    You can erase pencil lines.

 

Yes,   I can see that you have made some improvements  already.    Keep up the good work.

If you are unsure about something,   just ask.

 

David.

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


kembou kevin wrote:
to be able to do the calculations on the values ​​sampled by the cs5530 you have to do a 24-bit binary conversion to decimal.

A 24-bit number is just a 32-bit number in which the highest byte is all zeros[1].

 

There is no need to "convert to decimal" - the processor works in binary.

 

[1] maybe all ones - if it's signed & negative.

 

EDIT

 

Apart from the datasheet, have you looked at the other resources provided by Cirrus?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Jan 25, 2022 - 09:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

NB I changed the thread title to something more "manageable" so it wouldn't mess up the display of forum message titles!

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

 For brevity example see #35.  There is a lot lot more to be done.  You are fast burying yourself in a quicksand avalanche of code.  For a program that isn't doing too much yet, you already have 80-90 different print statements?

Maybe step back and really scrub each code portion thoroughly before being tempted to cut & paste with a vengeance (yes, it is hard to resist that temptation). You will thank yourself for making the extra effort!

Each time you iterate, you will find ways to be more efficient in delivering the results. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

hi, kembou kevin can you post your working code here? I'm also stucked in the same problem

Yasir Shahzad

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

can you post your working code here? 

He hasn't been back much since, so generally doubtful.  What issue do you have 7 & what have you actually tried? 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Jul 5, 2022 - 01:44 AM