Cannot write to ADC registers

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

Hello,

I posted a problem with ADC sample speed a few days ago and people pointed out to me that the limited speed was no surprise as it was all written with ASF code.

Now I got rid of the ASF code and callback function and I also changed the ADC initialization from ASF to writing the registers directly, which does not work.

I can write to other IO registers, but not to ADC registers.

I put two write operations in succession, the assembly code is the same for both operations, register 0x0601 is written to, register 0x0241 not. I have no idea why. Please help.

	PORTA_DIRSET = BIT(6);
00000E41  LDI R24,0x40		Load immediate 
00000E42  STS 0x0601,R24		Store direct to data space 
	ADCB_CTRLB = BIT(6);
00000E44  STS 0x0241,R24		Store direct to data space 

 

This topic has a solution.

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

Always a good idea to say which chip you are using, people may not be willing to go to another thread to find out the chip used.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

sorry,

its a ATxmegaA3BU.

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

It IS doing the write to that address, just as it's doing the op to the other address so how can you say it's not doing the write ? Since the value is ALREADY in R24 from previous code line, it just needs to store it. Try it in the simulator.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Thu. Jan 29, 2015 - 09:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The debugger stopped right behind the two write commands:

Register 0x0601 is written:

Register 0x0241 is not written:

What do I overlook here?

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

ok, I found that one of the ASF-initialisation routines prohibited me from writing into the ADC registers.

	irq_initialize_vectors();
	cpu_irq_enable();
	board_init();
	sysclk_init();
	pmic_init();
	sleepmgr_init();

I haven't had the time yet to find out which one exactly is the cause. When I comment them out completely I am able to write to the register in question.

I will mark as answered.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi !

I think that the culprit is sysclk_init(). I think that Atmel wanted to copy the behaviour of Cortex-M processors: on power-on on Cortex-M processors, all peripherals are OFF, this is hardware. On the XMEGA, this is not the case. So the sysclk_init() function disable all the unused peripherals. And when a peripheral is OFF, you cannot write to its registers. You should look for PR.PRPA or PR.PRPB and enable the ADC there.

Also, since you are debugging, why do you look at the memory view, instead of using the provided processor view (which is much more conveninent btw) ?

Have a nice day,
Kraal

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

Note that my comments regarding the Cortex-M behaviour may not be partially, nor completely true. If some Cortex-M specialist can correct me if needed, that would be great.

Have a nice day,
Kraal

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

Hello Kraal,

yes, that was it, thank you so much.

I was looking for some kind of lockbit in the manual but did not find the power registers.