Writing registers from arduino IDE bombs sketch.

Status
Not open for further replies.

ottojas

New member
I have been trying to activate one of the analogue comparitor ports and associated interrupt.
When I write to any of the com0 control registers my program goes off to never-never land.
Regardless of the order they are presented in. Writing to any of the registers
CMP0_MUXCR, CMP0_CR0, CMP0_CR1, CMP0_DACCR, CMP0_SCR and several other
unrelated registers defined as "*(volatile uint8_t *)" in mk20dx128.h, cause the system to fail.
The following program prints "Start Debug" to the serial monitor and then nothing else.

I am new to arduino ide and teensy3.0, but not to programming, electronics
and microprocessors. Am I stumbling over some little obvious fact? Any help greatly appreciated.

Otto

///////////////////////////////////////////////////////////////////////////////
#include "mk20dx128.h"
#include "core_pins.h"


void setup()
{
delay(5000);
Serial.begin(9600);
Serial.print("Start Debug\n");
Serial.flush();

CMP0_MUXCR = 0x7;
Serial.print("3. Wrote CMP0_MUXCR\n");
Serial.flush();

CMP0_CR0 = 1 << 4;
Serial.print("5. Wrote CMP0_CR0\n");
Serial.flush();

CMP0_CR1 = 1 << 4; // | 1;
Serial.print("6. Wrote CMP0_CR1\n");
Serial.flush();CMP0_CR1 = 1 << 4; // | 1;

CMP0_DACCR = 1 << 7 | 1 << 6 | 0x1F; //DACEN=7 VRSEL=6
Serial.print("2. Wrote DACCR\n");
Serial.flush();

CMP0_SCR = 1 << 4 | 1 << 2;
Serial.print("4. Wrote CMP0_SCR\n");
Serial.flush();
}

void loop()
{
delay(1000);
}
//////////////////////////////////////////////////////////
 
Problem partially solved. These constants are within a bit-band region. If anyone interested, i will post sample code for using bit-band regions here.
What looked like a real address in the .h file is not and needs special treatment. The acces generates a fault since the address is outside the range
of the processor.

It would be nice to have some macros available to make acessing bin-banded regions easier.
 
Status
Not open for further replies.
Back
Top