Hi,
I want to connect NetBurner MOD5270 (devKit) to a Quadravox QT531 (MP3 player) using RS232 on UART0.
NetBurner COM0 is a DB9 female and Quadravox QT531 input is also a DB9 female.
I use a gender changer to connect my NetBurner to the Quadravox but nothing works.
I simply use OpenSerial function. Do I have to put specific jumper on the NetBurner (JP6 / JP13).
Is the gender changer a problem ? I have no idea.
Do I need to rewrite a serial driver ?
Code:
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <NetworkDebug.h>
#include <iosys.h>
#include <serial.h>
extern "C"
{
void UserMain(void * pd);
}
const char * AppName="Quadravox";
#define QUADRAVOX_RESET 0x27
#define QUADRAVOX_PLAY 0x00
char buffer[64];
void UserMain(void * pd)
{
InitializeStack();
if (EthernetIP == 0)
GetDHCPAddress();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();
StartHTTP();
#ifdef _DEBUG
InitializeNetworkGDB_and_Wait();
#endif
SerialClose(0);
while (1)
{
OSTimeDly(TICKS_PER_SECOND);
int fd0 = OpenSerial(0, 9600, 1, 8, eParityNone);
SerialEnableTxFlow(0, 0);
SerialEnableRxFlow(0, 0);
SerialEnableHwTxFlow(0, 1);
SerialEnableHwRxFlow(0, 1);
Serial485HalfDupMode(0, 0);
if (fd0 > 0)
{
buffer[0] = QUADRAVOX_RESET;
int writeBytes = writeall(fd0, buffer, 1);
int readBytes = ReadWithTimeout(fd0, buffer, 64, TICKS_PER_SECOND*5);
buffer[0] = QUADRAVOX_PLAY + 1;
writeBytes = writeall(fd0, buffer, 1);
readBytes = ReadWithTimeout(fd0, buffer, 64, TICKS_PER_SECOND*5);
SerialClose(0);
}
}
}
Connect NetBurner MOD5270 (DevKit) to external RS232 Device
Re: Connect NetBurner MOD5270 (DevKit) to external RS232 Device
If the both RS232 connections are female then you need a Null modem connector. A gender changer will not work since it does not swap the RX, TX and flow control signals. This page has good info on db9 pinouts and null modem connectors:
http://www.lammertbies.nl/comm/cable/RS-232.html
Do not call Serial485HalfDupMode unless you are using 485. You are putting the port into 485 full duplex mode. There is no reason to call SerialEnableTxFlow or SerialEnableRxFlow, though they should have no effect on your code.
I am also not sure if you are aware how ReadWithTimeout fully works. This function will block until either there has been a timeout or until at least 1 char has been read. Which ever of these two events happens first will end the read. If you want a 64-byte read from the device after your write then you should make a loop to do the full read:
int TotalReadBytes = 0;
while( TotalReadBytes < 64 )
{
int readBytes = ReadWithTimeout(fd0, buffer+TotalReadBytes , 64-TotalReadBytes , TICKS_PER_SECOND*5);
if( readBytes <= 0 )// we had an error or timeout
break;
else
TotalReadBytes += readBytes;
}
http://www.lammertbies.nl/comm/cable/RS-232.html
Do not call Serial485HalfDupMode unless you are using 485. You are putting the port into 485 full duplex mode. There is no reason to call SerialEnableTxFlow or SerialEnableRxFlow, though they should have no effect on your code.
I am also not sure if you are aware how ReadWithTimeout fully works. This function will block until either there has been a timeout or until at least 1 char has been read. Which ever of these two events happens first will end the read. If you want a 64-byte read from the device after your write then you should make a loop to do the full read:
int TotalReadBytes = 0;
while( TotalReadBytes < 64 )
{
int readBytes = ReadWithTimeout(fd0, buffer+TotalReadBytes , 64-TotalReadBytes , TICKS_PER_SECOND*5);
if( readBytes <= 0 )// we had an error or timeout
break;
else
TotalReadBytes += readBytes;
}
Re: Connect NetBurner MOD5270 (DevKit) to external RS232 Device
If you haven't already try to connect and control the device from a PC using HyperTerminal or MTTY. I would think that would be a good first step to make sure you have the cabling and protocols correct.
Re: Connect NetBurner MOD5270 (DevKit) to external RS232 Device
Thanks a lot lgitlitz,
I create a home-made DB9 male/male null-modem cable based on the DB9 pin-out connectors and I am now able to communicate with the Quadravox device.
Your help was really appreciate.
I create a home-made DB9 male/male null-modem cable based on the DB9 pin-out connectors and I am now able to communicate with the Quadravox device.
Your help was really appreciate.