How do I write sketch code to display UART Register contents on the debug console?

Status
Not open for further replies.

BradleyC

Active member
I confess to being a noob with Arduino/Teensyduino - not a noob to embedded development or Cortex M, however.

Should it be possible to read any UART1 register and display it with code similar to that shown below that attempts to read the UART_BDH register?

On the register access, the sketch appears to hang.

No further progress through the routines called from Setup() seems to occur judging from the expected progress displays sent to Serial.print(). (I have not put the OScope on pins)


Code:
#define MAX483CTL 9             // Pin 9 controls MAX483 direction. LOW enables Reception, HIGH, transmission
void setupComms( void ) {

  uint8_t rval;
  
  // the existing RS-485 system runs at 19200.
  Serial.println("setupComms() - Serial1");
  Serial1.begin( 19200 );
  Serial1.transmitterEnable( MAX483CTL ); // Pin 9 controls MAX483 direction. LOW enables Reception, HIGH, transmission
 
  delay(500);

  Serial.println("going to read a UART register now.");
   
  rval = *((uint8_t *)0x4006B000);

  Serial.println("read the value ok."); // FIXME - code never reaches here.

  Serial.print("Contents of UART1_BDH was: "); Serial.println(rval, HEX);
  
  return;
}

While the "going to read a UART register now." appears on Serial console, the message "read the value ok." never appears.

The program appears to behave as if a machine check or memory protection trap has occurred with a the trap handler that executes a 'jump here' loop.
 
Might help to know which Teensy you are trying to read this for?

But regardless, the issue is you are trying to access registers associated with Serial2 object.

That is Serial1 uses KINETISK_UART0

So you have not enabled access to that range of memory.

In order to enable the memory for that range of memory you would need to enable the associated clock.
For Serial2 (your range of memory).

SIM_SCGC4 |= SIM_SCGC4_UART1

If you want to look at Uart0 associated with Serial1, the address would be:
rval = *((uint8_t *)0x4006A000);

And to enable access to this memory you would need: SIM_SCGC4 |= SIM_SCGC4_UART0;
Which is the first thing that Serial1.begin(...) does.
 
Oops. The pre-edited post named my device: Teensy 3.2.

I'm using Serial1 for RS-485 communication.

I was unaware of the mapping of Arduino Serial1 to the MCU's UART0. That explains the likely machine check! THANK YOU!

First time I used a Cortex M4 device I discovered this 'separate clock enables for each peripheral device' feature.

All processors I'd coded before had one clock enable -- this was my first low power application and I didn't choose the MCU but got thrown into the project long after the HW was designed and had to code the BSP without my standard homework of absorbing the CPU reference manual.

Lazily, I did the same thing here -- because I didn't need to do the BSP at all with Teensyduino having taken care of all of that.


I had assumed this mapping: Serial=UART0, Serial1=UART1, Serial2=UART2, etc.

Details matter. I should not have assumed.

Thanks again.
 
Status
Not open for further replies.
Back
Top