2014-02-03 01:43 AM
Hello everyone,
I am the new one at programming stm32f3. I saw multiple examples here on the forum but I did not find what I want. I have stm32f3 discovery board and ublox GPS connected to PD8 (Tx) and PD9 (Rx) pins. I want to read data from pins and show it on pc on terminal. I have connected stm32f3 discovery to PC via USB. For programming I use Keil uVision. Has anybody of you some code for this or can help me how to do that please? Please help. Best regards Grega #nmea #c-basics #parser #fsm #design #state-machine #c-learning2014-02-04 01:06 AM
2014-02-06 02:59 AM
Hello,
I have another problem...with clive1`s code I get the data to pins PA2 and PA3 on STM32F3discovery board. I want to show data on PC terminal via ''usb user'' on stm32f3discovery board. I was looking at schematics of stm32f3disco board how pins are connected and i didn`t understand it well. Can you help me how to do that please? There is a picture: http://i62.tinypic.com/fdc2g7.jpg Best regards2014-02-06 03:24 AM
Hi
''I want to show data on PC terminal via ''usb user'' on stm32f3discovery board. I was looking at schematics of stm32f3disco board how pins are connected and i didn`t understand it well. Can you help me how to do that please?'' ''// USB-to-Serial Port
// USART2-TX PA2
// USART2-RX PA3
// GPS on Sheild Slot 1
// USART3-TX PD8
// USART3-RX PD9
''
Right now - your GPS is on USART 3 as input. If you look in the data sheet (NOT the reference manual) for the STM32 part, there is a section which lists the pin out. This table shows which pins has which IO port/pin and which peripherals can be connected to that pin (Not all pins can connect to all peripherals).
From the code snipet from clive1 - it looks like you are using a USART to USB convertor and the USB convertor is plugged into you PC. Is that right?
''I want to show data on PC terminal via ''usb user'' on stm32f3discovery board. ''
Are you asking - how can I use the USB on the STM32 instead of the USB convertor?
To Use the USB peripheral on the STM32 - you need to
1) add the correct USB library (OTG or FullSpeed I think are the options) to your project
2) decide on what type of implementation (Host or device) - in your case it will be device
3) decide on which device type - in your case CDC
4) correctly configure the USB library/drivers.
5) modify the driver to handle you input/ouput.
2014-02-06 03:49 AM
2014-02-06 04:13 AM
Hi
''Do you have some example code for using USB peripheral?'' http://www.st.com/st-web-ui/active/en/catalog/tools/PF258154 This link has all the example code from STmicro for your board. There is a USB example for HID (Human Interface Device eg mouse, keyboard etc) http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257882 This link is for the STMicro USB OTG library/drivers. In there, there is an example for USB CDC. ''What is CDC?'' USB communications device class. It is a USB device class for serial comms. http://en.wikipedia.org/wiki/USB_communications_device_class2014-02-06 08:04 AM
I added to the clive1`s code:
char Buff[256]={0}; unsigned int lenght=0; Set_System(); Set_USBClock(); USB_Interrupts_Config(); USB_Init(); lenght = sprintf(Buff,'' %c '',USART_ReceiveData(USART3)); CDC_Send_DATA(Buff,lenght); On the PC terminal I saw the data, but it disappeared really fast and then appeared really fast again. Is maybe something wrong with baudrate? There is a picture of data seen on terminal: http://i59.tinypic.com/ve5351.jpg2014-02-06 08:14 AM
Hi
Is that your main loop? ''lenght'' should be length. ''lenght = sprintf(Buff,'' %c '',USART_ReceiveData(USART3));'' Do some debugging. I think you will find that reading the uart is not emptying the buffer and the length is always some number, ie not zero. That is why you see ''On the PC terminal I saw the data, but it disappeared really fast and then appeared really fast again.'' ''Is maybe something wrong with baudrate?'' No. You need a better way to detect when new characters appear and not send anything to USB until there are new characters.2014-02-06 08:25 AM
Yes, this is main loop.
Do you have some advice for better way to detect when new characters appear? Please help. Correct my code if you have idea please.2014-02-06 08:59 AM
Hi
''Correct my code if you have idea please.'' Sorry, I do not have the time to read, analyse and correct your code for you. You need to do it. ''Do you have some advice for better way to detect when new characters appear? Please help.'' Yes, I can help by giving advice. Assuming the USART is interrupt based. First look at your code the USART. Make sure it has a receive buffer. Make sure it has a send buffer. When sending characters - make sure they are marked as sent or taken out of the buffer. When recieving characters - make sure that as inserted into the buffer. Have a function for USART to send data which fills the buffer. Have a function to read from USART which copies the read buffer out and empties the data copied out. When the code is changing the buffer - make sure the IRQ cannot trigger. Do the same thing with the USB CDC driver.2014-02-06 09:06 AM
@Clive1, chief, can you help me please? As I said, I am an amateur and I don`t know how to do that. Please, help.