0
\$\begingroup\$

I am using

STM32f401rct6 microcontroller - master (No Commands)

and LTC6811 battery Monitoring IC- Slave (Multiple Commands)

I have developed full firmware perfectly including drivers. But i have a small doubt in SPI Interface between Stm32f401rct6 microcontroller. I have understood the concept of SPI also perfectly.i understood that SPI interface is all about transmitting data Through Shift registers

SPI Specs:

Full Duplex

Master mode

1 Mhz of Clock

CPOL High

CPHA High

hardware Slave management

But my doubt is i would like to receive data from the slave (LTC6811) but I have No Command for master To Send. But i have Multiple command for slave as mentioned Below,

Slave Commands:

LTC6811_adcv(); // For Measuring each Cell voltges from 10 cell battery pack.

LTC6811_rdcv(); // Reads and parses the LTC6811 cell voltage registers.

LTC6811_adax(); // for Measureing GPIO of Slave IC LTC6811

LTC6811_rdaux(); // Reads and parses the LTC6811 GPIO registers.

LTC6811_clear_discharge() // Discharges the Cell voltages which reaches the threshold voltages.

I want to receive Cell Voltage Measurement and GPIO Measurement .By using Cell Voltage Measurement data i need to discharge the cell voltages which is reaching more than threshold voltage.

Since there is No Command to send from master i am sending a Dummy byte to receive the data . But my Doubt is i Have multiple Slave command So Should i send seperate Dummy byte for cell voltage measurement command and seperate Dummy Byte for GPIO Measurement command and seperate dummy bytes for other commands to receive all the datas in the loop or How should i receive data Kindly Suggest Me a Solution Since iam a beginner kindly help me.

I havent Implemented the SPI Receive or Dummy Byte Code Based on the suggestions i will Implement.

main.c Code:

#define DATALOG_DISABLED 0

#define DATALOG_ENABLED 1

#define N_IC 1

uint8_t count=1;

cell_asic bms_ic[N_IC];

const uint8_t TOTAL_IC = N_IC;

int main(void)
{
const uint16_t UV=UV_THRESHOLD;
const uint16_t OV=OV_THRESHOLD;
// initialize the SPI2 GPIO
GPIO_Inits();
// initialize the SPI2 GPIO
SPI2_GPIO_Inits();
// initialize the SPI2
SPI2_Inits();
//  This Function sets the SSOE bit to 1 Which helps  the Chip select Pin to automatically  sets Low
SPI_SSOEConfig(SPI2, ENABLE);

// initialising LTC6811
LTC6811_init_cfg(TOTAL_IC,bms_ic);
for(uint8_t current_ic = 0 ; current_ic<TOTAL_IC ; current_ic++)
{
LTC6811_set_cfgr(current_ic,bms_ic,REFON,ADCOPT,gpioBits_a,dccBits_a,dctoBits,UV,OV);
}
LTC6811_reset_crc_count(TOTAL_IC,bms_ic);
LTC6811_init_reg_limits(TOTAL_IC,bms_ic);
//Loop for all the LTC6811 Commands to run


while(1)
{
uint8_t error = 0;
wakeup_sleep(TOTAL_IC); // Enabling Slave ( battery monitoring IC)

// Slave Commands

//  Cell voltage measurement
LTC6811_adcv(ADC_CONVERSION_MODE,ADC_DCP,CELL_CH_ALL);
error = LTC6811_rdcv(REG_ALL,TOTAL_IC,bms_ic);
check_error(error);
print_cells(DATALOG_DISABLED);

//  AUX(GPIO) measurement
LTC6811_adax(ADC_CONV_MODE,AUX_CH_GPIO5);
error = LTC6811_rdaux(NO_OF_REG,TOTAL_IC,bms_ic);
check_error(error);
print_aux(DATALOG_DISABLED);

// Get Cell Max Min Function for Passive cell balancing

get_cell_max_min();

//Passive Cell Balancing code for each cells.

//   This clears all the DCC Bits before or after Discharge process by setting the counter
if(count >=1 && count < 13)
{
LTC6811_clear_discharge(TOTAL_IC,bms_ic);
}
count = 0;
}
}
\$\endgroup\$
  • \$\begingroup\$ It would seem that you should simply invent some means for the master to ask for a certain kind of data? Instead of a dummy byte, send a code corresponding to a data type. \$\endgroup\$ – Lundin Aug 14 at 6:52
  • \$\begingroup\$ Thank you so much for your reply . Send a code in the sense like send a byte getting ACK OR Nack and then sending a dummy byte to receive a data are you taking about this code if not kindly explain me \$\endgroup\$ – Muthu Aug 14 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.