I'm trying to migrate a C code to a code that works in Arduino. I don't have much experience in programming in Arduino and there are some expressions that I am not able to make work.
I have a function that initializes the MCU and sets some parameters:
/* Below functions are used to initialize MCU Platform */
uint32_t MCUPlatformInit(void *pCfg)
{
int UrtCfg(int iBaud);
/*Stop watch dog timer(ADuCM3029)*/
pADI_WDT0->CTL = 0xC9;
/* Clock Configure */
pADI_CLKG0_OSC->KEY = 0xCB14; // Select HFOSC as system clock.
pADI_CLKG0_OSC->CTL = // Int 32khz LFOSC selected in LFMUX
BITM_CLKG_OSC_CTL_HFOSCEN|BITM_CLKG_OSC_CTL_HFXTALEN;
while((pADI_CLKG0_OSC->CTL&BITM_CLKG_OSC_CTL_HFXTALOK) == 0);
pADI_CLKG0_OSC->KEY = 0xCB14;
pADI_CLKG0_CLK->CTL0 = 0x201; /* Select XTAL as system clock */
pADI_CLKG0_CLK->CTL1 = 0; // ACLK,PCLK,HCLK divided by 1
pADI_CLKG0_CLK->CTL5 = 0x00; // Enable clock to all peripherals - no clock gating
UrtCfg(230400);/*Baud rate: 230400*/
return 1;
}
And when I compile I get this error but I don't know how to declare these parameters and how to use them:
C:\Users\Documents\Arduino Code\main\main.ino: In function 'uint32_t MCUPlatformInit(void*)':
main:37:3: error: 'pADI_WDT0' was not declared in this scope
pADI_WDT0->CTL = 0xC9;
If someone could help me and guide me to rewrite this function so that it works in Arduino I would be very grateful.
Hello psendra5,
Welcome to the Arduino fora.
Before you do anything else please take a moment to read General guidance and How to use this forum
Especially item #7 on posting code.
Please edit your original post to include code tags as per the instructions.
You need to to provide more information:
I'm trying to migrate a C code to a code that works in Arduino.
Migrate from what to which Arduino? Different Arduinos use different processors.
The parameters in that function are for initialising registers, as gcjr says they are most likely different as this will be for a different processor. That said, if it is a different processor you can't just change the register names, you have to understand what the code does and configure it differently for a different processor to achieve what you want.
Most of the code, bar perhaps setting the speed of the serial port, is to do with setting up the processor. All that stuff is done behind the scenes for you on Arduino.
Unfortunately you're probably going to find a similar issue with converting the rest of the code. It's all going to be hardware specific to the target processor.
PerryBebbington:
Hello psendra5,
Welcome to the Arduino fora.
Before you do anything else please take a moment to read General guidance and How to use this forum
Especially item #7 on posting code.
Please edit your original post to include code tags as per the instructions.
You need to to provide more information:Migrate from what to which Arduino? Different Arduinos use different processors.
The parameters in that function are for initialising registers, as gcjr says they are most likely different as this will be for a different processor. That said, if it is a different processor you can't just change the register names, you have to understand what the code does and configure it differently for a different processor to achieve what you want.
This is a code provided for a device compatible with an Arduino UNO. This code is originally used to program an evaluation board that replaces the Arduino UNO and my intention is to migrate this code to Arduino to remove the evaluation board and use an Arduino UNO.
The company that distributes this device and provides this original code explains that the code is ready to be used with other MCUs and that you only have to modify this type of functions and that is why I thought that it should not be a very complicated task.
For more information, this is an AD5941 board (which is ready to be used with an Arduino) from Analog Devices and my intention is to replace the EVAL-AD5940 board by an Arduino UNO.
This is a code provided for a device compatible with an Arduino UNO
What device?
The company that distributes this device
What company?
The code is ready to be used with other MCUs
If the code relies on things specific to the MCU, such as register definitions, the porting to a different processor is not an easy task. You would need to fully understand the code, how it used the registers on one MCU and then write equivalent code for the target processor. One of the features of the Arduino world is that the processor level stuff is already done for you, making code (mostly) portable, within reason. However, that does not appear to the be the case here.
For more information, this is an AD5941 board
Have you looked at the datasheet for the AD5941? It is described as a 'High Precision, Impedance & Electrochemical Front End, which is nothing like any Arduino, it is not an MCU. Is that what you were expecting?
The EVAL-AD5940 looks like it should work with a Uno, but you cannot replace an EVAL-AD5940 with a Uno.
PerryBebbington:
Have you looked at the datasheet for the AD5941? It is described as a 'High Precision, Impedance & Electrochemical Front End, which is nothing like any Arduino, it is not an MCU. Is that what you were expecting?
The EVAL-AD5940 looks like it should work with a Uno, but you cannot replace an EVAL-AD5940 with a Uno.
The device I want to replace is the EVAL-AD5940 board from Analog Devices. This device is the MCU and what I would like to do is to replace it with an Arduino and modify the code that I provided earlier, which is used to program the EVAl-AD5940 device to work with an Arduino UNO.
To make the system work properly, I should program the Arduino UNO with the code of the EVAL-AD5940 board and then connect the Arduino UNO to the AD5940 device that already has the connectors that are compatible with the Arduino UNO pins.
I am trying to follow the instructions provided in this section. But I've started with the "Porting Functions in main.c" part and I'm trying to write the function
/* Below functions are used to initialize MCU Platform */
uint32_t MCUPlatformInit(void *pCfg)
{
int UrtCfg(int iBaud);
/*Stop watch dog timer(ADuCM3029)*/
pADI_WDT0->CTL = 0xC9;
/* Clock Configure */
pADI_CLKG0_OSC->KEY = 0xCB14; // Select HFOSC as system clock.
pADI_CLKG0_OSC->CTL = // Int 32khz LFOSC selected in LFMUX
BITM_CLKG_OSC_CTL_HFOSCEN|BITM_CLKG_OSC_CTL_HFXTALEN;
while((pADI_CLKG0_OSC->CTL&BITM_CLKG_OSC_CTL_HFXTALOK) == 0);
pADI_CLKG0_OSC->KEY = 0xCB14;
pADI_CLKG0_CLK->CTL0 = 0x201; /* Select XTAL as system clock */
pADI_CLKG0_CLK->CTL1 = 0; // ACLK,PCLK,HCLK divided by 1
pADI_CLKG0_CLK->CTL5 = 0x00; // Enable clock to all peripherals - no clock gating
UrtCfg(230400);/*Baud rate: 230400*/
return 1;
}
with Arduino. According to the user guide I have to modify all the functions that appear in the link you have attached, but I don't understand if I have to measure all the functions ("main.c" and "ADICUP3029Port.c" files or I only have to modify the ones in "ADICUP3029Port.c".
Well, my advice is free. You can ignore it if you wish, of course. I hope you find re-writing the Arduino core initialization functions fun, even though they already exist and have been improved and maintained for many years, and the source code is in the public domain.
aarg:
Well, my advice is free. You can ignore it if you wish, of course. I hope you find re-writing the Arduino core initialization functions fun, even though they already exist and have been improved and maintained for many years, and the source code is in the public domain.
So, if I have understood correctly, you are telling me that it is not necessary to implement the functions of the "main.c" file because Arduino already has these initialization functions automatically?
And that I should only focus on modifying the functions of the "ADICUP3029Port.c" file?
I'm sorry if I'm not understanding very well what you want to tell me but I'm a little new to this world and the truth is that I'm having a hard time adapting and understanding everything I have to do, but still, thank you very much for the time you're taking to help me.
psendra5:
So, if I have understood correctly, you are telling me that it is not necessary to implement the functions of the "main.c" file because Arduino already has these initialization functions automatically?
And that I should only focus on modifying the functions of the "ADICUP3029Port.c" file?