Int mani(void) and setup

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

Hello all,

 

Im programming code to an atmega328. Im using serial comunication to read sensors, and i got an error if use:

 

int main(void){
...
 while(1){
...
 }
}

 

If use this code, the communications "lost sync with device"

 

 

But if use:

 

void setup(){
...
}
void loop(){
...
}

 

All works fine with this arduino formated code. But i prefer the other code, anyone know what is the problem? I already see the difference on google but no luck.

 

 

Thanks

 

edit [

its not really an error. All program its building fine and the program into atmega dont return any error.

The program needs to receive info from analog sensors with serial communication with USB. The communication its based on robotic operating system, and when i enter the code to start reading and send information to PC they work fine but the program stop the sync with device sometimes and auto reconnect (cause a pick for 1 secound on sensor reading).

But if i use the "arduino setup and loop funtions" the communications never fails, so i think theres some code behind the setup and the loop of arduino that makes the program dont stop. Something about watchdog? I dont know.

]

 

 

Last Edited: Fri. Apr 20, 2018 - 03:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What environment are you programming in? The Arduino IDE? Or Studio 7? Or something else?

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

Hello, im using Arduino IDE on ubuntu because its easily to install the libraries of robot operating system.

 

Thanks

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

Then setup a separate IDE (Code::Blocks, Eclipse (CDT), Netbeans, etc) and use that to wrap around the compiler installed by Arduino or just get another one by googling for "Atmel toolchain for Linux".

 

You are best doing Arduino thing in Arduino and plain C or C++ things in a plain IDE+compiler.

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

Joao Pinto wrote:
the (sic) communications "lost sync with device"  

What communications?

 

Where & when, exactly, does this message appear?

 

As Cliff suggests, the Arduino IDE expects things to be done in The Arduino Way - so, if you don't do that, you are likely to break it!!

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

The Arduino IDE already provides you with:

int main(void)
{
	init();

	initVariant();

#if defined(USBCON)
	USBDevice.attach();
#endif
	
	setup();
    
	for (;;) {
		loop();
		if (serialEventRun) serialEventRun();
	}
        
	return 0;
}

A main()

if you want to bypass it for some reason, you can just place all you code in Setup()

 

Jim

 

Mission: Improving the readiness of hams world wide : flinthillsradioinc.com

Interests: Ham Radio, Solar power, futures & currency trading - whats yours?

 

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

As far as I know that main() that Jim shows is defined as a "weak link" so if you want to totally over-ride it you should just be able to implement a main() in a INO and that will be used instead. Of course if you do it like that (and don't call the Arduino internal init() code) then you can't expect things reliant on timers and ADCs and stuff to be available. OTOH if you are implementing main() you presumably plan to do it all "from scratch" anyway?

 

I do wonder what

Joao Pinto wrote:
, and i got an error if use:

actually means? As I say I think you should be able to just implement main() anyway - so what was the EXACT wording of any error messages shown?

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

Thanks ki0bk, but i already try something like that.

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

I just tried this:

 

As you can see a sketch with no setup() / loop() (hidden behind "#if 0") but just a single enabled main() seems to build just fine. So I'm still interested to know what your errors were when you tried this?

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

In my 20+ years of programming in C / C++ I have done a handfull of blinking led projects with "arduino".

One was with the "arduino java contraption editor" (not an ide), which went in the garbage bin within half an hour.

 

The others were test cases for platformio to test different software & hardware configurations.

If you start an "arduino" project with platformio, you can use a normal int main (void) { } function even though it already exists somewhere hidden in the arduino stuff.

I did not get errors / warnings about multiple definitions of main() which I found strange, but I did not look too deep into it to understand all the details.

 

Do you get any compilation errors?

Does your main( ) function get exectued at all?

Where does that "lost sync with device" error come from?

It could be that you have to have do some stuff manually (maybe enable interrupts or some other hardware)

 

I have not used plaftormio much yet, I just experimented with a bunch of different combinations ( AVR, ESP8266, STM32, arduino, mbed, CMSIS) but It gets updated fairly often.

I just did a "pio update" (Which tells platformio to update itself) and this was it's response:

paul@dualcore:~$ pio update
****************************************************************************************************************************************
Obsolete PIO Core v3.5.1 is used (previous was 3.5.3a1)
Please remove multiple PIO Cores from a system:
http://docs.platformio.org/page/faq.html#multiple-pio-cores-in-a-system
****************************************************************************************************************************************
Updating tool-scons                      @ 3.20501.2      [Up-to-date]
Updating tool-unity                      @ 1.20302.1      [Up-to-date]
Updating contrib-pysite                  @ 0.2.0          [Up-to-date]
Updating contrib-piohome                 @ 0.9.5          [Up-to-date]
Updating tool-pioplus                    @ 1.1.7          [Up-to-date]

Platform Manager
================
Platform Atmel AVR
--------
Updating atmelavr                        @ 1.8.1          [1.8.2]
Uninstalling atmelavr @ 1.8.1: 	[OK]
PlatformManager: Installing atmelavr @ 1.8.2
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
atmelavr @ 1.8.2 has been successfully installed!
Updating toolchain-atmelavr              @ 1.40902.0      [Up-to-date]
Updating framework-arduinoavr            @ 1.10620.2      [Up-to-date]
Updating tool-avrdude                    @ 1.60300.2      [Up-to-date]

Platform Espressif 8266
--------
Updating espressif8266                   @ 1.6.0          [Up-to-date]
Updating tool-mkspiffs                   @ 1.200.0        [Up-to-date]
Updating tool-esptool                    @ 1.409.0        [Up-to-date]
Updating tool-espotapy                   @ 1.1.0          [Up-to-date]
Updating framework-arduinoespressif8266  @ 1.20400.0      [1.20400.3]
Uninstalling framework-arduinoespressif8266 @ 1.20400.0: 	[OK]
PackageManager: Installing framework-arduinoespressif8266 @ 1.20400.3
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
framework-arduinoespressif8266 @ 1.20400.3 has been successfully installed!
Updating toolchain-xtensa                @ 1.40802.0      [Up-to-date]

Platform ST STM32
--------
Updating ststm32                         @ 3.8.0          [4.2.0]
Uninstalling ststm32 @ 3.8.0: 	[OK]
PlatformManager: Installing ststm32 @ 4.2.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
ststm32 @ 4.2.0 has been successfully installed!
Updating tool-stm32duino                 @ 1.0.0          [Up-to-date]
Updating framework-libopencm3            @ 1.1.0          [Up-to-date]
Updating toolchain-gccarmnoneeabi        @ 1.60301.0      [1.70201.0]
Uninstalling toolchain-gccarmnoneeabi @ 1.60301.0: 	[OK]
PackageManager: Installing toolchain-gccarmnoneeabi @ 1.70201.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
toolchain-gccarmnoneeabi @ 1.70201.0 has been successfully installed!
Updating framework-cmsis                 @ 1.40300.0      [Up-to-date]
Uninstalling framework-arduinoststm32 @ 2.0.170723: 	[OK]
Uninstalling framework-mbed @ 4.50701.0: 	[OK]
Uninstalling framework-stm32cube @ 1.0.0: 	[OK]
Uninstalling tool-stlink @ 1.10301.1: 	[OK]
Uninstalling toolchain-gccarmnoneeabi @ 1.40804.0: 	[OK]
PackageManager: Installing framework-arduinoststm32 @ ~2.1.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
framework-arduinoststm32 @ 2.1.180219 has been successfully installed!
PackageManager: Installing tool-stlink @ ~1.10400.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
tool-stlink @ 1.10400.0 has been successfully installed!
PackageManager: Installing framework-stm32cube @ ~1.2.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
framework-stm32cube @ 1.2.0 has been successfully installed!
PackageManager: Installing framework-mbed @ ~4.50802.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
framework-mbed @ 4.50802.0 has been successfully installed!

Library Manager
===============

No hassle, no errors, it all seems to work as it should.

The only improvement above this is if an "apt update" would also update platformio.

 

Then I did a "pio lib search ROS" and this is it's output:

paul@dualcore:~$ pio lib search ROS
****************************************************************************************************************************************
Obsolete PIO Core v3.5.1 is used (previous was 3.5.3a1)
Please remove multiple PIO Cores from a system:
http://docs.platformio.org/page/faq.html#multiple-pio-cores-in-a-system
****************************************************************************************************************************************
Found 8 libraries:

ros_lib_indigo
==============
#ID: 5195
ROS Serial library for Mbed platforms for ROS Indigo Igloo. Check http://wiki.ros.org/rosserial_mbed/ for more information

Keywords: ros
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: Gary Servin

ros_lib_jade
============
#ID: 5196
ROS Serial library for Mbed platforms for ROS Jade Turtle. Check http://wiki.ros.org/rosserial_mbed/ for more information.

Keywords: ros
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: Gary Servin

ros_lib_kinetic
===============
#ID: 5197
ROS Serial library for Mbed platforms for ROS Kinetic Kame. Check http://wiki.ros.org/rosserial_mbed/ for more information.

Keywords: ros
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: Gary Servin

Rosserial Arduino Library
=========================
#ID: 1634
Use an Arduino as a ROS publisher/subscriber

Keywords: communication
Compatible frameworks: Arduino
Compatible platforms: Atmel AVR
Authors: Michael Ferguson, Joshua Frank

rosserial_hydro
===============
#ID: 5198
rosserial library for mbed Inspired by nucho's rosserial library This library is still under development

Keywords: ros_serial, ros, hydro
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: Akash Vibhute

rosserial_arduino
=================
#ID: 345
An implementation of the rosserial protocol for Arduino

Keywords: rosserial
Compatible frameworks: Arduino
Compatible platforms: Atmel AVR, Atmel SAM, Espressif 8266, Intel ARC32, Microchip PIC32, Nordic nRF51, Teensy, TI MSP430
Authors: Open Agriculture Initiative

rosserial_mbed
==============
#ID: 977
An implementation of the rosserial protocol for Mbed Platforms

Keywords: rosserial
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Nordic nRF51, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy
Authors: PabloPL

SerialDriver
============
#ID: 2682
Buffered Serial Port Driver for RTOS

Keywords: uart, buffered, serial, ros
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: BlazeX

Platformio  has some knowledge of several thousand software libraries, and the same update command I did above will also check for updates of all the libraries you have installed.

 

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

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

Hi Clawson, its not really an error. All program its building fine and the program into atmega dont return any error.

The program needs to receive info from analog sensors with serial communication with USB. The communication its based on robotic operating system, and when i enter the code to start reading and send information to PC they work fine but the program stop the sync with device sometimes and auto reconnect (cause a pick for 1 secound on sensor reading).

But if i use the "arduino setup and loop funtions" the communications never fails, so i think theres some code behind the setup and the loop of arduino that makes the program dont stop. Something about watchdog? I dont know.

 

Thanks for all

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

Thanks Paulvdh.

That is usefull.

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

Joao Pinto wrote:
But if i use the "arduino setup and loop funtions" the communications never fails, so i think theres some code behind the setup and the loop of arduino that makes the program dont stop. Something about watchdog? I dont know.
I'm guessing it's more likely to do with the "hidden" interrupts that the Arduino infrastructure has going off all the time.

 

But surely the point about going the main() route is that you now take "complete control". Nothing is "hidden" so if something fails it's because of a bug in YOUR code not some hidden code that someone else is providing.

 

I would suggest that when you get to the point of "robotics" there is a pretty strong chance that your module interactions become so complex that it would be very difficult to debug without an invasive debugger. I'd get an Atmel ICE. Of course if you do that I think it's fairly unquestionable that the "best" debugging environment then becomes Studio 7 so it all starts to force you down the Windows route. In Linux you can have a crack with avr-gdb on top of avarice but it can prove "tricky".

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

I have installed both the "command line" version of platformio and the "IDE" version.

If you come from the "arduino java contraption" I recommend to install the IDE version of platformio if you want to use it ( It comes default with "atom" as IDE), but I was already used to another IDE and therefore the command line version is better suited for me, because it can be integrated in any ide you like.

But integration of platformio in Atom is probably better. For example it comes with a plugin with which you can install the libraries and update it with a few mouse clicks.

 

If you want to try platformio, then please write a short review of your opinion after you have used it for a while (good or bad) and tag it along on this thread:

https://www.avrfreaks.net/forum/platformio-do-or-do-not-thats-question?skey=platformio%20do%20or%20do%20not

 

I have no stock or other affiliation in platformio.

Some time ago I thought I was interested in ESP8266, and it was hard to find anything to find that was not "arduino" based for it. I found the java contraptrion horrible, and went searching for something "better", and that is how I found platformio.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

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

Thanks again Clawson, usually i build on Atmel studio but at internship i cant use windows or ever app "not free". I using the enterprise PC with ubuntu so im using Arduino IDE, but im installing netbeans as you suggest. I ll see with more attention my code.

Just to clarify i don't use Arduino board, just the atmega and a shipper ISP programmer (asp) in this project.

 

Really thanks again.

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

Totally agree with Clawson that te Atme-ICE is probably the most comfortable way for debugging, but I bade farewell to windows a long time ago and only use linux. I found out that a USD 5 Logic Analyser can be a very usable substitute for an ICE. I wrote a bit of background on how I use a LA in:

https://www.avrfreaks.net/forum/led-indicator-software-debugging

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

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

Paulvdh wrote:
I found out that a USD 5 Logic Analyser can be a very usable substitute for an ICE.

Eh????

 

While in do way denying that a logic analyser is an extremely valuable & powerful tool, it is in no way a substitute for an ICE - they address 2 totally different areas of the system.

 

Use both!

 

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

awneil wrote:
they address 2 totally different areas of the system.
The way I use my LA (in the link from post #17) I put debug breadcrumbs on a LA trace and this can be easily augmented with dumping variables through any uart or SPI. This is very much alike to single stepping and setting watches on variables, with the additional benefits that everything is logged by the LA. You can search backwards in your data.

 

awneil wrote:
Use both!
Neither me nor OP are running windows at the moment. trying to use Atmel-ICE gets ... complicated.

But large parts of an AVR program can be debugged on a PC, by compiling with a "regular" C compiler.

 

Not to OP:

In the arduino programming environment a mix of C and C++ is used, and there are a bunch of pre-instantiated static C++ classes. The constructors of those classes get called before the main( ) function is executed. That may be a hint to the difference.

Also: There are different versions of main() in an "arduino" program, depending on the exact configuration. Most have a simple:

while( 1) {
    loop( );
}

But some have a:

while( 1) {
    Check_Something_With_Serial_events( );
    loop( );
}

They also have a global interrupt enable in main( ).

The most logical is that you forgot the sei().

With netbeans, Atom or any other decent IDE you can do a simple search for the main( ) function or references to the loop( ) function.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

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

Paulvdh wrote:
I put debug breadcrumbs on a LA trace and this can be easily augmented with dumping variables through any uart or SPI. This is very much alike to single stepping and setting watches on variables

No, it's not.

 

You have to rebuild & reload your code with these features added.

 

The whole point of the ICE is that it gives you direct access to all this stuff without having to modify the code.

 

Again, not to say that it isn't all good & useful stuff - just that it is very much a different approach.

 

The 2 approaches are complementary - both are useful; both have different pros & cons.

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

if i use the "arduino setup and loop funtions" the communications never fails, so i think theres some code behind the setup and the loop

 There is an init() function that happens before setup() that initializes the ADC, Timers, and Serial port in a way compatible with the arduino libraries.

If you override setuo() and loop() by providing your own main() function, this init() won't be called, and you won't be able to use most of the arduino core and library function (and in particular, Serial won't work) unless  you somehow replace them with the equivalent.  This was pointed out back in reply #6 https://www.avrfreaks.net/comment/2451926#comment-2451926

Overriding the Arduino main() became possible back around version 1.5 (several years ago, now.)

 

i already try something like that.

Please show us what your code actually looks like...

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

westfw wrote:

 

i already try something like that.

Please show us what your code actually looks like...

 

Exactly. Was init() called in that code?

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

Hello everyone, thanks for answers. 

 

Im using my own funtion to config my ADC, INT and TIMERS. Than i call that funtion on main() and use sei() to set global interrupts. As youi can see the resume of that:

 

 

//include 

    ...

//ROS configs to publish and subcrive 

//define vars

 

void cfg_ADC(){
   //config ADC
}
 

int main(void)
{
  cfg_ADC(); 
   
  sei();
   
  ADCSRA |= (1<<ADSC); 
  

 //ROS node set
  
  while (1)
  {
     //ROS subscrive and publish vars
     
  }

 

ISR(ADC_vect)

}

 

This way the conection ll restart, if subs int main for void setup and while(1) for void loop, the conection never fails.

Both program never return an error of compile or sending to micro.

 

Thanks

 

Last Edited: Sat. Apr 21, 2018 - 01:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the first line of main(), call init():

 

int main(void)
{
    init();
    cfg_ADC();
    etc...

Test if it makes any difference.

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

Thanks, i ll try nest monday, the hardware its at work

 

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

 

What does

if (serialEventRun) serialEventRun();

do? (it is the only extra line added to loop by Arduino ide and is somewhat crypic for me)

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

dbrion0606 wrote:
What does if (serialEventRun) serialEventRun(); do?
well it's checking a function pointer to be non-0 before calling through it. Arriving at 0 on an AVR is never a good experience and presumably the author keeps 0 in the function pointer when it hasn't been assigned so it's kind of acting as its own flag to say "has been set".

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

It's what is sometimes called a 'callback'.

 

Quote:

In computer programming, a callback is any executable code that is passed as an argument to other code, which is expected to call back the argument at a given time.

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Then , serialeventrun can be is coded by the user if needed (and can be empty/non existing if it has no use)?

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

dbrion0606 wrote:

Then , serialeventrun can be is coded by the user if needed (and can be empty/non existing if it has no use)?

 

 

Correct. It's a way of adding user code into other code without having to alter the original code.

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Oh, I want to thank you and Clawson (I had been puzzled with this line for months  -decided to play with other hw than Arduini, more simple- and OPs issue seems almost solved : dared to hijack his topic)

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

Hi El Tangas i include de init funtions but the system still losing conections between avr and pc.

 

Thanks

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

That is very strange indeed. So if you use setup and loop it works, but main doesn't even if you call init.

 

In that case, I only see one solution: use the default Arduino main():

 

// Declared weak in Arduino.h to allow user redefinitions.
int atexit(void (* /*func*/ )()) { return 0; }

// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }

void setupUSB() __attribute__((weak));
void setupUSB() { }

int main(void)
{
	init();

	initVariant();

#if defined(USBCON)
	USBDevice.attach();
#endif
	
	setup();
    
	for (;;) {
		loop();
		if (serialEventRun) serialEventRun();
	}
        
	return 0;
}

Use this with your loop and setup functions. This is identical with using loop and setup alone, so it has to work. Then start commenting out stuff in main() (other than the calls to setup and loop, of course) until it breaks.