-
Usart
Posted by
paul8454
on 06 Jun, 2016 08:10
-
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
-
#1 Reply
Posted by
paul8454
on 06 Jun, 2016 12:48
-
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
while(!SERCOM0->USART.INTFLAG.bit.DRE);
I don't understand why my orders ( here A for exemple) on the terminal are not taken considered
-
#2 Reply
Posted by
ajb
on 06 Jun, 2016 12:53
-
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.
-
#3 Reply
Posted by
paul8454
on 06 Jun, 2016 13:07
-
Ok so I made the modification but my orderis not handled by the terminal why?
By reducing F_CPU ,my instructions are not processed
-
#4 Reply
Posted by
ataradov
on 06 Jun, 2016 16:22
-
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.
-
#5 Reply
Posted by
paul8454
on 06 Jun, 2016 16:43
-
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.
your code will always print "Bye", since you will never be able to press a button fast enough.
-
#6 Reply
Posted by
ataradov
on 06 Jun, 2016 16:46
-
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.
-
#7 Reply
Posted by
paul8454
on 06 Jun, 2016 17:03
-
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()
-
#8 Reply
Posted by
ataradov
on 06 Jun, 2016 17:08
-
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.
-
#9 Reply
Posted by
ataradov
on 06 Jun, 2016 17:25
-
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?
-
#10 Reply
Posted by
ataradov
on 06 Jun, 2016 17:53
-
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.
-
#11 Reply
Posted by
ataradov
on 06 Jun, 2016 17:55
-
-
#12 Reply
Posted by
paul8454
on 06 Jun, 2016 18:10
-
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.
-
#13 Reply
Posted by
ataradov
on 06 Jun, 2016 18:13
-
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.
-
#14 Reply
Posted by
ataradov
on 06 Jun, 2016 18:30
-
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.
-
#15 Reply
Posted by
westfw
on 06 Jun, 2016 18:34
-
-
#16 Reply
Posted by
ataradov
on 06 Jun, 2016 18:35
-
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.
-
#17 Reply
Posted by
ataradov
on 06 Jun, 2016 18:38
-
Show your complete code. There is something wrong with SERCOM initialization, so it does not work.
-
#18 Reply
Posted by
ataradov
on 06 Jun, 2016 18:43
-
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.
-
#19 Reply
Posted by
ataradov
on 06 Jun, 2016 18:49
-
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.
-
#20 Reply
Posted by
ataradov
on 06 Jun, 2016 18:50
-
Also, which is it D11 or D10? The title says D10, your post says D11. They are different devices and are not binary compatible.
-
#21 Reply
Posted by
ataradov
on 06 Jun, 2016 19:01
-
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.
-
#22 Reply
Posted by
paul8454
on 06 Jun, 2016 19:14
-
can you tell me what's wrong, please?
-
#23 Reply
Posted by
ataradov
on 06 Jun, 2016 19:16
-
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.
-
#24 Reply
Posted by
paul8454
on 06 Jun, 2016 19:19
-
Well imagine that I take your project. and I want to make the current main that you advise me to do?