Write to USART1 UEXT on SAM7X256

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Timoses
Posts: 8
Joined: Thu Jul 19, 2012 11:51 am

Write to USART1 UEXT on SAM7X256

Post by Timoses »

Hi there..

First of all, I'm not very experienced with Microcontrollers. Though, I'd need some help and hope that you might be able to help me : >...

I'm trying to send bytes to the UEXT peripheral connector using the writeUSART(unsigned char* memPtr, unsigned int length) function. Sadly, I'm not getting it to work.
I'm trying to change the code which works with the USART0 part (meaning you can connect to the RS232 and the byte sending stuff works) to get it to work with the USART1 (UEXT).

I've tried:

- in main.c : sdStart(&SD2, &default_config);
using the &SD2 here instead of &SD1

- in serial_lld.c in function usart_init(void): AT91PS_USART pUSART0 = AT91C_BASE_US1;
instead of AT91C_BASE_US0;

Defines:

Code: Select all

// defines for USART interface.
#define USE_SD_DMA
//#define USE_SD_DMA_INTERRUPT            
//#define USE_SD_ENDTX_Interrupt         
#define CH_HAL_USE_SERIAL         TRUE   

#define SD_MODE                        ( AT91C_US_USMODE_RS485 + AT91C_US_NBSTOP_1_BIT + AT91C_US_PAR_EVEN + AT91C_US_CHRL_8_BITS + AT91C_US_CLKS_CLOCK )
#define SD_BAUDRATE                     115200   
#define SD_DMA_BUFFERSIZE               12800
#define SD_DMA_SENDBUFFERSIZE            50
#define SD_MAX_RECEIVEBUFFER            4



Hardware being used:
Microcontroller: SAM7-EX256 Rev. C - https://www.olimex.com/dev/sam7-ex256.html
for the UEXT: MOD-USB-RS232 - https://www.olimex.com/dev/mod-usb-rs232.html (do jumpers need to be set? I wouldn't know how (by soldering??))

I'd be thankful for any help!
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Been thanked: 1 time

Re: Write to USART1 UEXT on SAM7X256

Post by mabl »

Hi Timoses,
without ever having used a SAM7 - but just looking at the schematic: Are you using Ethernet? It looks to me that RXD1 is used by the PHY and the UEXT connector at the same time.
Timoses
Posts: 8
Joined: Thu Jul 19, 2012 11:51 am

Re: Write to USART1 UEXT on SAM7X256

Post by Timoses »

Hi mabl,
thanks for the answer : ).

The Ethernet adapter isn't connected at all. Also, in the user manual of the SAM7X256 under point 7.6 there is no talk about a connection of the RS232 with the Ethernet.

The connection from the microcontroller to the device is as follows:
(The UEXT Extension connector can be seen on page 11 of the user manual (https://www.olimex.com/dev/pdf/ARM/ATMEL/SAM7-EX256.pdf) )

MC -> (UEXT Extension connecter) -> MOD-USB-RS232 -> (USB) -> Weinmann USB-RS485 Converter -> Device


I believe that no jumpers (4 available) are set on the MOD-USB-RS232 since there are no resistors soldered. Is it neccessary to set jumpers?


Links:
Microcontroller: SAM7-EX256 Rev. C - https://www.olimex.com/dev/sam7-ex256.html
for the UEXT: MOD-USB-RS232 - https://www.olimex.com/dev/mod-usb-rs232.html
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Been thanked: 1 time

Re: Write to USART1 UEXT on SAM7X256

Post by mabl »

Hi Timoses,

true, I also did not see it mention in the manual - but it's clearly there in the schematics ;) Anyway, you setup is a bit strange anyway:

You use the MOD-USB-RS232 for RS232 to USB conversion - so far so good. There are solderjumpers on the MOD-USB-RS232 - but I don't think you need them.

What I do not understand is how you plan to connect the USB-RS485 Converter. You will need a computer in between - you cannot just connect two USB devices with a cable.

Also, are you connecting to some kind of medical device? You might want to think about isolating that RS485 connection. You could skip those RS232->USB<->USB->RS485 stuff and just use this:
http://olimex.wordpress.com/2012/07/12/ ... -in-stock/

But probably you first have to get the RS232 to work anyway.... I'm out of ideas. Maybe Giovanni knows the platform better.
Timoses
Posts: 8
Joined: Thu Jul 19, 2012 11:51 am

Re: Write to USART1 UEXT on SAM7X256

Post by Timoses »

Hi mabl,

from the MOD-USB-RS232 I have something like this (http://www.amazon.co.uk/StarTech-com-Mi ... B002O1S8IE) connected, where I then can plug in the USB-RS485 (http://www.weinmann.de/fileadmin/wm_de/ ... 113_en.pdf).

And yes indeed, it's a medical device.. Which shouldn't be of any difference though ^^..

Hm... It's not possible to just connect the MOD-USB-RS232 to the USB-RS485?
Right now, I can't think of any reason why that shouldn't work.. But lighten me up on that.


Hm.. another idea would be to connect the TXD1 and GND of the UEXT to a RS232 DB9 to USB connector and check with H-Term whether I receive anything, thus something being transmitted via UEXT.. ??
(This setup works if I just connect the RS232 DB9 connector from the Microcontroller's RS232 Connector to the PC, I then can see the received bytes with H-Term..)
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Been thanked: 1 time

Re: Write to USART1 UEXT on SAM7X256

Post by mabl »

Timoses wrote:And yes indeed, it's a medical device.. Which shouldn't be of any difference though ^^..

Depending on what you want to do, you might get ground loops. That's why I proposed the isolation.

Timoses wrote:from the MOD-USB-RS232 I have something like this (http://www.amazon.co.uk/StarTech-com-Mi ... B002O1S8IE) connected, where I then can plug in the USB-RS485 (http://www.weinmann.de/fileadmin/wm_de/ ... 113_en.pdf).

Hm... It's not possible to just connect the MOD-USB-RS232 to the USB-RS485?
Right now, I can't think of any reason why that shouldn't work.. But lighten me up on that.

This will not work, since USB is a bus. You must have a master,typically the PC. All other devices are slaves. You cannot connect a slave with a slave. Practically you would also have to teach the MOD-USB-RS232 how to talk the USB-RS485.

Timoses wrote:Hm.. another idea would be to connect the TXD1 and GND of the UEXT to a RS232 DB9 to USB connector and check with H-Term whether I receive anything, thus something being transmitted via UEXT.. ??
(This setup works if I just connect the RS232 DB9 connector from the Microcontroller's RS232 Connector to the PC, I then can see the received bytes with H-Term..)

It's a good idea to check with the computer if the board sends something. Just connect the MOD-USB-RS232. What you can NOT do is to connect the TXD1 directly to a DB9 connector. RS232 uses -12V and +12V logic levels - where as the micro-controller uses only 0V/3.3V. You might destroy your controller that way.
Timoses
Posts: 8
Joined: Thu Jul 19, 2012 11:51 am

Re: Write to USART1 UEXT on SAM7X256

Post by Timoses »

Hi mabl,
thank you for the quick replies.

mabl wrote:This will not work, since USB is a bus. You must have a master,typically the PC. All other devices are slaves. You cannot connect a slave with a slave. Practically you would also have to teach the MOD-USB-RS232 how to talk the USB-RS485.


Shouldn't the MOD-USB-RS232 handle this? In the user manual (introduction on page 2 https://www.olimex.com/dev/OTHER/MOD-US ... -RS232.pdf) is talk about a host and a device mode. Are you absolutely sure that this won't work? If so the inability of my supervisor is once again proven...

mabl wrote:You might destroy your controller that way.

Thanks for the hint.
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Been thanked: 1 time

Re: Write to USART1 UEXT on SAM7X256

Post by mabl »

Timoses wrote:Hi mabl,
thank you for the quick replies.

mabl wrote:This will not work, since USB is a bus. You must have a master,typically the PC. All other devices are slaves. You cannot connect a slave with a slave. Practically you would also have to teach the MOD-USB-RS232 how to talk the USB-RS485.


Shouldn't the MOD-USB-RS232 handle this? In the user manual (introduction on page 2 https://www.olimex.com/dev/OTHER/MOD-US ... -RS232.pdf) is talk about a host and a device mode. Are you absolutely sure that this won't work? If so the inability of my supervisor is once again proven...

The host/device mode just refers to how the RS232 Recieve and transmit path connect to the UEXT connector. So basically you can swap TX/RX if you need to. So you can either connect to a board where the MOD-USB-RS232 is the device. Or you could connect some other UEXT device to the MOD-USB-RS232. In that case, you'll have to make the MOD-USB-RS232 behave like a board/host.

But this does NOT refer to the USB Host mode in any way. I'm 99.99% sure it will never work that way.

In your case I'd:
  • Use the MOD-USB-RS232 for development. Connect the USB to your computer and see if you can talk to your board.
  • Once you are confident you implement your protocol correctly, swap the MOD-USB-RS232 for a MOD-RS485 or
    MOD-RS485-ISO and connect it directly to your medical device.
  • If it does not work, check the termination resistors of the provided USB->RS485 converter and make the Olimex converter behave the same.
Timoses
Posts: 8
Joined: Thu Jul 19, 2012 11:51 am

Re: Write to USART1 UEXT on SAM7X256

Post by Timoses »

Hey there again.

Alright, I now tried to connect the MOD-USB-RS232 to the PC.
I tried it with a USBAM-USBAM which kinda looks like this one: http://www.alibaba.com/product-gs/56990 ... e_for.html

Unfortunately, no new COM-Port is detected. I tried plugging the MC in and out, executing the program ...

Any suggestions? Am I using the wrong adapter?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Write to USART1 UEXT on SAM7X256

Post by Giovanni »

It is not clear to me your software setup, in ChibiOS there is not a function called writeUSART(). Is it possible you are mixing different things?

Giovanni
Post Reply