1

How can i set the baud rate to 2MBaud in C source code on Windows / Visual Studio 2010.

dcb.BaudRate = 2000000UL; //doesn't work.

Data sending at least works, tested using a serial port monitor. My microcontroller and it's ftdi chip is also working fine with 2mbaud using Bray's terminal.

Is there any possibility to find out the current settings of a com port?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Thomas
  • 1,468
  • 4
  • 14
  • 20
  • 1
    Have you read though [the "How to Ask" guide here on Stack Overflow](http://stackoverflow.com/questions/how-to-ask)? (Helpful hint: nobody here can read your mind.) – In silico May 02 '12 at 10:58
  • That's not a standard baudrate, much too high for real hardware. Small odds that a custom driver implements it. If it does then it is typically a virtual serial port and the baudrate doesn't matter at all. Not providing any details at all in the question prevents a decent answer, voting to close. – Hans Passant May 02 '12 at 11:34
  • FTDI usb-serial converters can handle up to 3MBaud ;) – Thomas May 02 '12 at 11:54

2 Answers2

0

Look at GetCommState() and SetCommState() API's and the DCB struct.

Martin James
  • 24,453
  • 3
  • 36
  • 60
0
DCB dcb;
dcb.BaudRate = 2000000;
...
SetCommState(hFile, &dcb);

At least that's how I interpret "Assigns an actual baud rate or an index by specifying a CBR_ constant" from here.

Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
  • Thanks, I'm actually trying this, but the microcontroller is not answering anything. It works with Terminal or Matlab serial ports and a Serial Port Monitor is telling me that the correct data was sent. Btw, 2Mbaud are possible because of using FT232 usb-serial converter. – Thomas May 02 '12 at 11:53
  • @Thomas: Are you sure your microcontroller's serial port is capable of working at such a speed? Also, do you need to take into account RTS/CTS/DTR/DSR? – Alexey Frunze May 02 '12 at 12:01
  • @Alex: Yes I'm sure. Everything works when i use MATLAB serial classes or Brays Terminal – Thomas May 02 '12 at 12:04
  • Is there any possibility to find out the current dcb settings of an opened port via some external software? – Thomas May 02 '12 at 12:08
  • This is a new question. Try SystemInternals' ProcessMonitor. – harper May 02 '12 at 12:23
  • OK, just to go over all that. Using your app, the Serial Port Monitor is showing that the correct data was sent to the uC? What is a 'Serial Port Monitor' - is it a separate hardware box? – Martin James May 02 '12 at 12:36
  • I'm using this serial port monitor: http://www.serial-port-monitor.com/index.html – Thomas May 02 '12 at 12:55
  • OK, so it's software and so doesn't mean much. I would go with hardware here. Send a stream of 0x55 or 0xAA, shove a storage scope on the tx pin and, (if the data is coming out at all), measure the bit width. – Martin James May 02 '12 at 13:02
  • Also. please define 'doesn't work'. Does the uC UART rxData interrupt or error interrupt fire at all? – Martin James May 02 '12 at 13:49
  • My scope shows that the baudrate using my c++ is more than 100x slower than using the 2mbaud with the terminal app which is working very good. I'm really sure that something doesn't work when i set dcb.Baudrate = 2000000 – Thomas May 02 '12 at 13:55
  • yea writing now works. problem was that the number 2.000.000 was set during initializing a global var, when i set it directly before setting dbc it works. thanks for your help! – Thomas May 02 '12 at 14:19
  • 2
    ..and your problem has now moved - what was it that overwrote the global var and what is it overwriting now? :) – Martin James May 02 '12 at 15:36