Author Topic: Usart  (Read 7774 times)

0 Members and 1 Guest are viewing this topic.

Offline paul8454Topic starter

  • Contributor
  • Posts: 16
  • Country: fr
Usart
« on: June 06, 2016, 08:10:31 am »
Hello,

I want to implement a serial communication between my PC and my card. I just want to initialize  USART

If anyone can help me ...

Thank you
« Last Edit: June 07, 2016, 07:13:14 am by paul8454 »
 

Offline paul8454Topic starter

  • Contributor
  • Posts: 16
  • Country: fr
Re: SERCOM USART SAMD10
« Reply #1 on: June 06, 2016, 12:48:06 pm »

When I write on the Windows terminal, the command doesn't send, so I'll necessarily in the else and I stay blocked in this loop
Code: [Select]
while(!SERCOM0->USART.INTFLAG.bit.DRE);
I don't understand why my orders ( here A for exemple) on the terminal are not taken considered
 

Online ajb

  • Super Contributor
  • ***
  • Posts: 2604
  • Country: us
Re: SERCOM USART SAMD10
« Reply #2 on: June 06, 2016, 12:53:58 pm »
I haven't looked at your SERCOM configuration in detail since it's been a while since I messed with SAMD series, but you're powering on the peripheral and hooking it up to a clock, so that's good. 

Two much more fundamental problems jump out, though:

1) You're calling writeData_uart with a string instead of the 8 bit uint that it expects.  I think you meant to call uart_send_string.  Your compiler should be giving you warnings about this.

2) You have the code that handles the UART before the main while(1) loop.  That means that the only time your MCU could possible receive and respond to any UART data is the time between enabling the UART and getting to your "if" statement.  At 48MHz, that's going to be a few hundred nanoseconds at absolute most, while it takes about one millisecond to transmit a single character at 9600 baud, so there's no way your MCU will ever manage to catch a character before it hits the empty while loop!  You need to move the whole if() block inside the while loop.
 

Offline paul8454Topic starter

  • Contributor
  • Posts: 16
  • Country: fr
Re: SERCOM USART SAMD10
« Reply #3 on: June 06, 2016, 01:07:26 pm »
Ok so I made the modification but my orderis not handled by the terminal why?
By reducing F_CPU ,my instructions are not processed
« Last Edit: June 07, 2016, 07:14:10 am by paul8454 »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #4 on: June 06, 2016, 04:22:07 pm »
There is a number of problems with your code:
1. You never initialize the pins to be connected to SERCOM module, so it never gets to send or receive anything. The code looks a lot like my MCU starter projects, so look for HAL macros in the same place and they are there for a reason.
2. Your readData_uart() simply reads the contents of the DATA register without waiting for something to be there. So after you correct item 1, your code will always print "Bye", since you will never be able to press a button fast enough.

Alex
 

Offline paul8454Topic starter

  • Contributor
  • Posts: 16
  • Country: fr
USART
« Reply #5 on: June 06, 2016, 04:43:21 pm »
Code: [Select]
Your read_uart() simply reads the contents of the DATA register without waiting for something to be there.
With the read function, it expects something on the part of Windows terminal. It should read my character I understand that communication between the character back into the terminal and my code don't interact.But the character is not sent to the terminal.
Code: [Select]
your code will always print "Bye", since you will never be able to press a button fast enough.

« Last Edit: June 07, 2016, 07:15:37 am by paul8454 »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #6 on: June 06, 2016, 04:46:54 pm »
I have to change the CPU frequency? But so what value I can go down?
Where did you get this idea from? Although, yes, your frequency may also be incorrect at the moment. That depends on what SystemInit() is doing.

Where did you get this code from? Why not use full working code first and go from there?

I use the table below
You configured SERCOM module itself, but you did not configure PORT (GPIO) module to release pins to SERCOM.

With the read function, it expects something on the part of Windows terminal. It should read my character 'A' I understand that communication between the character back into the terminal and my code don't interact.But the character 'A' is not sent to the terminal.
You need to wait for a flag that there is a byte in the data register and then read that register. Just like you are waiting for a flag that indicated that register is empty before you send a new byte.

PS: Please don't quote with code tags.
« Last Edit: June 06, 2016, 04:50:08 pm by ataradov »
Alex
 

Offline paul8454Topic starter

  • Contributor
  • Posts: 16
  • Country: fr
USART
« Reply #7 on: June 06, 2016, 05:03:19 pm »
Quote
You configured SERCOM module itself, but you did not configure PORT (GPIO) module to release pins to SERCOM.

I must add this code of configure port in the function uarIinit()




« Last Edit: June 07, 2016, 07:17:21 am by paul8454 »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #8 on: June 06, 2016, 05:08:33 pm »
PORT->Group[1].PINCFG[4].bit.PMUXEN = 1;
PORT->Group[1].PINCFG[5].bit.PMUXEN = 1;
Something like this. I have not checked exact numbers, since I wrote macros once and I don't ever want to think about this again.

You will also need to select actual PMUX value. Seriously, look at my hal_gpio.h file. It is a single file that will do all that work for you.

But there are a lot of files that are associated
In my projects there are exactly 3 files that matter. The rest of them are standard header files, you don't need to do anything with them and they also  present in your ASF project.

I must add this code in main before if...
No in the main(), in the receive byte function. You want to wait for a new character every time you want to receive something, not just once.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #9 on: June 06, 2016, 05:25:05 pm »
the characters are not sent
I'm not going to check your magic numbers. It is a waste of my time, use hal_gpio.h, or waste your own time on your own.

Take the whole project from https://github.com/ataradov/mcu-starter-projects/tree/master/samd11 . It is a fully self contained project that is known to work. And start your modifications from there.

Right now, do you know that your SystemInit() configures the system for 48 MHz?
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #10 on: June 06, 2016, 05:53:45 pm »
You need to take the whole project. Don't just add files to your existing project. In this case you are missing a linker script, which provides all those missing symbols.

Alternatively you can take two files (main and hal_gpio.h), and skip the startup file. But in this case you will have to rename interrupt handler name for the timer (otherwise you won't see LED blinking). And you may need to do some other cleanups.

Learning to reuse other people's code is an important part of embedded development. Don't just discard the whole thing if something did not work right away.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #11 on: June 06, 2016, 05:55:33 pm »
Alex
 

Offline paul8454Topic starter

  • Contributor
  • Posts: 16
  • Country: fr
Re: SERCOM USART SAMD10
« Reply #12 on: June 06, 2016, 06:10:42 pm »
Yes it's good thank you I launched the demo with the LED blinking. But I find it far too complex for my little program, pines, I just use the code above.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #13 on: June 06, 2016, 06:13:27 pm »
You find my simple starter project too complex? That's like the simplest thing you can do.

Is there something specifically you don't understand about it?

ASF code includes all the same parts and more. You just don't see them if you specifically don't look for them.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #14 on: June 06, 2016, 06:30:29 pm »
1. Do usart_send_string() at the beginning of the program (just like the original one does). This will let you test that sending works. There is no point in trying to receive the data if you can't send anything.

2. When 1 works, show us how you readData_uart() is implemented.

There is no point of sending screnshoot, send actual the code.
Alex
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: SERCOM USART SAMD10
« Reply #15 on: June 06, 2016, 06:34:46 pm »
Also see here: https://github.com/WestfW/SAMD10-experiments/blob/master/D10-LED_TOGGLE0/src/UserSource/hardwareserial.c
for some simple, non-ASF UART code for the SAMD10 Xplained Mini.  You might have to filter out the arduino-like pin indirection.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #16 on: June 06, 2016, 06:35:11 pm »
Well, again, you defined F_CPU to 48 MHz. My projects are designed for 8 MHz and sys_init() sets 8 MHz frequency.

I strongly suggest starting entirely with my projects. You are creating problems for yourself by trying to use a mix of ASF and register-based code.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #17 on: June 06, 2016, 06:38:44 pm »
Show your complete code. There is something wrong with SERCOM initialization, so it does not work.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #18 on: June 06, 2016, 06:43:30 pm »
On D10 Xplained board, UART is connected to pins A10 and A11. Why are you trying to configure pins PB8 and PB9 (they don't even exist on this device)?

That's it. I'm not going to respond anymore until you start using GPIO macros from hal_gpio.h. I've created them to not waste my time, and you are doing exactly this by no using them.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #19 on: June 06, 2016, 06:49:15 pm »
I have three evaluation board I launched this code on SAMD11
That dose not explain why you are configuring the wrong pins.

I can't deal with this anymore. Take all the code from https://github.com/ataradov/mcu-starter-projects/tree/master/samd10 and try to run that. Without any changes at all. Don't take partial files, etc.

In your latest example, I don't see interrupt handler for the timer interrupt. The first timer interrupt that happens will create problems.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #20 on: June 06, 2016, 06:50:48 pm »
Also, which is it D11 or D10? The title says D10, your post says D11. They are different devices and are not binary compatible.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #21 on: June 06, 2016, 07:01:11 pm »
Quote
PORT->Group[1].
is a configuration for PORT B.  And pins 8 and 9 are the wrong pins for the board you are using. 0x22 may also be a wrong value, depending on your intent. I'm stopping here. You don't want to listen to a reasonable advice, deal with this on your own.
Alex
 

Offline paul8454Topic starter

  • Contributor
  • Posts: 16
  • Country: fr
Re: SERCOM USART SAMD10
« Reply #22 on: June 06, 2016, 07:14:01 pm »
can you tell me what's wrong, please?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: SERCOM USART SAMD10
« Reply #23 on: June 06, 2016, 07:16:40 pm »
You are configuring the wrong pins.  I can't tell what configuration is correct,  I have macros for this, I'm not going to reverse engineer them to tell you what values to write.  You don't have you use them,  but at least have a look at what they are doing.
Alex
 

Offline paul8454Topic starter

  • Contributor
  • Posts: 16
  • Country: fr
Re: SERCOM USART SAMD10
« Reply #24 on: June 06, 2016, 07:19:31 pm »

Well imagine that I take your project. and I want to make the current main that you advise me to do?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf