Author Topic: serial port  (Read 13590 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
serial port
« on: July 22, 2009, 04:02:31 PM »
Hi Mark,
  I have to communicate to a device at 1200 baud,1 start, 7 data bits,1 parity (even), 1 stop bit. Before I start communicating I have to send a break for 12ms , which is a high on the data pin.  Would the best way to do this is to set the serial to I/O, set the pin state, and after the 12ms set back into serial mode?

If so, what state are the TX/RX lines when changing to I/O (and visa versa)? Would it be better placing pullups/pulldowns so these are in a known state between changing modes?

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: serial port
« Reply #1 on: July 22, 2009, 09:07:25 PM »
Hi Neil

The Coldfire project should include break transmission support.

Activate UART_BREAK_SUPPORT, which will allows the serial operating mode to be set with BREAK_AFTER_TX. This would cause the break condition to automatically be sent after a buffer has been transmitted.

However you can also call the routines to do this directly with
extern void fnStartBreak(QUEUE_HANDLE channel);
and
extern void fnStopBreak(QUEUE_HANDLE channel);

channel is the number of the UART, eg. 0 for UART0.

Note that if you are simulating this the break condition will also be sent on the COM port!

Regards

Mark


Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: serial port
« Reply #2 on: July 22, 2009, 10:46:03 PM »
Hi Mark,
  Thanks for the reply. I am interfacing with a sdi12 which indicates a break (which is a space,binary zero) must be sent to wake up the device, then a commandis sent. So I assume I would call fnStartBreak(..), then my command.
How long does the break last, can It be set to 12ms?


Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: serial port
« Reply #3 on: July 23, 2009, 10:17:16 AM »
Hi Neil

The break is a condition with undefined length so you will need to first command the break, then wait the desired break time and then command the break condition off.

I haven't used this for some time but I think that also sending further data will automatically remove the break condition too.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: serial port
« Reply #4 on: August 04, 2009, 03:22:45 PM »
Hi Mark,
 I cant seem to get this to work. I have UART1 setup and have a logic analyser on the TX pin which is triggered on a High->Low transaction.  I simply want to create a break for x-milliseconds, then switch off. I know I have set the port up okay, as when I press a button on my board it sends out a letter 'N' on the com port, which my logic analyser detects. I have removed the sending of the letter 'N' and done the following:

//within m5223x.h
#define UART_BREAK_SUPPORT

//within my code..
  SerialChannel=1; //com serial channel
  ....
  ....
  fnStartBreak(SerialChannel);

 but after doing the above, the tx line doesnt change.

I am attempting to do the following:
 fnStartBreak(1); //set break , tx pin low.
 wait 20ms
 fnStartBreak(0); //set tx back high again, and wakes up sensor..
 wait 20ms
 ....
 ...
 Send tx commands now that the sensor is awake.


I have just tried sending 1 character, then fnStartBreak(1), and this works, but, it sends the break after a character is sent. I have to send a break on its own, then reset it.

Regards
Neil
« Last Edit: August 04, 2009, 03:46:31 PM by neil »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: serial port
« Reply #5 on: August 04, 2009, 10:22:09 PM »
Hi Neil

This sounds as though the command works only "after" a character has first been sent. This is unexpected and I will look into it.

Regards

Mark


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: serial port
« Reply #6 on: August 04, 2009, 11:11:35 PM »
Hi Neil

I looked into it and found the following.

1) You need to use fnStartBreak(1); and then fnStopBreak(1); to set the break condition on UART1 and then remove it (with the delay between).

2) This uses a UART command which is only accepted when teh transmitter is enabled - the transmitter is in fact disabled between transmissions and so only actually works when commanded directly after sending something (which is how it has in fact been used up to now, to automatically set a break condition to signal the end of a message transmission.

3) To allow the routines to operate unconditionally the following changes can be made in M5223X.c

- in extern void fnStartBreak(QUEUE_HANDLE channel)

    *ucReg = (UART_START_BRK | UART_TX_ENABLE);                          // start sending break on tx line

- in extern void fnStopBreak(QUEUE_HANDLE channel)

    *ucReg = (UART_STOP_BRK | UART_TX_DISABLE);                          // start sending break on tx line


This automatically enables and disables the transmitter when the break condition is set and cleared. I did some quick tests and it seems to work correctly when used independently of active transmission.

Please verify.

Thanks, regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: serial port
« Reply #7 on: August 05, 2009, 09:48:07 AM »
Hi Mark,
  Thanks for the reply, and it worked. The only thing the fnStopBreak() didnt bring the tx line back up. If I changed the  UART_TX_DISABLE to UART_TX_ENABLE, then it came back up again.

Regards
Neil

Offline syakovlev

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: serial port
« Reply #8 on: April 04, 2013, 09:04:02 PM »
In my experience it works exactly as Marc suggested:

*ucReg = (UART_START_BRK | UART_TX_ENABLE);                          // uart tx line goes low
*ucReg = (UART_STOP_BRK | UART_TX_DISABLE);                          // uart tx line goes high