Hi, i am having trouble with code, i have a raw code to test my connection between c2000 controller and encoder and now i just need to create .c and .h file to make it look more "beautiful", if there is someboody who can tell me how to do it i would be thankful the code for communication is:
/**
* \file main.c
* \brief Main file for the project
* \author Viktor
* \date 4th March 2021
*
* Last update: 4th March 2021
*
*/
#include <F2837xD_device.h>
#include "mcu.h"
/**
* \brief Delay function defined in \a F2837xD_usDelay.asm
*/
externvoid _F28x_usDelay(long LoopCount);
#define CPU_RATE 5.0L //!< Sets CPU rate for DELAY_US macro.
#define DELAY_US(A) _F28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L) //!< Sets CPU rate for DELAY_US macro.
#include"mcu.h"
#include"spi_communication.h"
unsignedint skusobnePole[10];
unsigned RxData[10];
unsigned PositionRaw = 0;
unsigned CRC_value = 0;
unsigned Error_bits = 0;
// main function
int main(void)
{
unsigned i = 0;
// initialize MCU clocks
mcu_initClocks();
for (i = 0; i < 10; i++)
{
RxData[i] = 0;
}
// initialize SPI
mcu_initSPI(500);
EALLOW;
//GpioCtrlRegs.GPBDIR.bit.GPIO58=1;
//GpioCtrlRegs.GPBDIR.bit.GPIO62=1;
EDIS;
while (1)
{
DELAY_US(200);
RxData[0] = spi_transmitChar(0);
RxData[1] = spi_transmitChar(0);
RxData[2] = spi_transmitChar(0);
RxData[3] = spi_transmitChar(0);
PositionRaw = ((RxData[0] & 0x07) << 10) | (RxData[1] << 2) | (RxData[2] & 0xC0);
Error_bits = (RxData[2] & 0x30) >> 4;
CRC_value = (RxData[2] & 0x0F << 2) | ((RxData[3] & 0xC0) >> 6);
}
return 0;
}
(I can't even remotely test the code because I don't have the 3rd party library/libraries needed.)
There are apps available, standalone or online, that can format source code to look better. Some IDEs (Integrated Development Environment) have that capability 'built-in.' Visual Studio is one.
by more "beautiful" i ment that in the main.c there will be only one function which will do what is from 54 to 60 line in code, so i am asking how it can be done
If'n that isn't helpful then I don't know what can be done since what you are trying to do isn't all that understandable.
The internet has a LOT of resources available, searching for what you want/need should be a first step. It is part of "asking questions the smart way."
Being a self-taught (and still learning) programming hobbyist I've had lots of questions how to do something across the years. Most times I've found what I'm looking for, or something close enough to work, by scraping the bowel of the interwebz.
The few times I couldn't find something on my own that worked I then began asking questions of others, starting off informing them what I had done in detail. More often than not answers were quick in coming.