powerofrecall wrote:I'm not getting any output. I'm assuming there is no way I have wired this wrong. Should RX be wired to TX and vice versa? I'm not using your exact code Minty but my code duplicates it and running it through the MESS debugger, it looks "proper."
For my serial in and out functions, I need to be waiting for RRDY bit to go low before reading a byte, and RRDY to go high before writing a byte, yes?
Yes, that is correct from memory. I may well put down the steps as Psuedocode to ensure that we are all on the right page.
Just a silly question: the connections and directions are from the perspective of the PC.
One option here to try out Tx from the MD which is Rx ONLY for the PC is to wire up ONLY the connections for the PC_Rx and see how that goes.
The MD_Tx is a lot more forgiving than to attempt MD_Rx first so try that first of all please.
powerofrecall wrote:
I'm using a FTDI usb serial adapter with TTL level, I have TX, RX and GND connected. It appears as a normal serial (/dev/ttyUSB0) in linux and I'm assuming functions like one.
I'm using cutecom as my terminal, are there any particular serial settings I need other than Baud = 1200?
Yes, I use an FTDI device but I also have the MAX232 connected to that so that only the MAX232 is connected directly to the MD.
Silly question: you have tried out your /dev/ttyUSB0 with another DevBoard or something that has an RS232 Port and it worked right?
I have not used cutecom I actually used Putty but I sampled the output from the transmission using my Logic-Analyser to see what was going on the lines too.
I could try that on Linux and see if I hit any issues for comparison but will have to do it tomorrow.
Can you confirm your RS232 Terminal Settings please?
8,1 stop?
powerofrecall wrote:
My C code looks something like this:
Code: Select all
#define PORT3_SCTRL 0xA1001F
#define PORT3_TX 0xA1001B
#define PORT3_RX 0xA1001D
uint8_t _inbyte(void) {
volatile uint8_t *pb;
uint8_t byte;
/* wait for RRDY low */
while(*pb & 0x02) pb = (volatile uint8_t *) PORT3_SCTRL;
pb = (volatile uint8_t *) PORT3_RX;
byte = *pb;
return byte;
}
void _outbyte(uint8_t c) {
volatile uint8_t *pb;
uint8_t byte;
byte = c;
/* wait for RRDY high */
while(!(*pb & 0x02)) pb = (volatile uint8_t *) PORT3_SCTRL;
pb = (volatile uint8_t *) PORT3_TX;
*pb = byte;
}
The initialization looks like this:
Code: Select all
void serial_init(void) {
volatile uint8_t *pb;
pb = (volatile uint8_t *) PORT3_SCTRL;
/* S-CTRL is for the status, etc. of each port's mode change, baud rate and SERIAL.
7 6 5 4 3 2 1 0
S-CTRL BPS1 BPS0 SIN SOUT RINT RERR RRDY TFUL */
*pb = 0xB0; /* 1200bps serial in/out enable */
}
Ok, what's the scope of the volatile uint8_t *pb ? What about if you have it as a global then pass it in to the serial_init.
void
serial_init(volatile uint8_t *pb)
Just a check as I cannot determine the variables scope from your code snippet.
Also, using an Emulator can you determine what the value of the SCTRL Register is after you have set it and also does your program essentially sit in the Super-Loop after you have executed all your Init code or does it simply fall through?
Your Code:
Code: Select all
void _outbyte(uint8_t c) {
volatile uint8_t *pb;
uint8_t byte;
byte = c;
/* wait for RRDY high */
while(!(*pb & 0x02)) pb = (volatile uint8_t *) PORT3_SCTRL;
pb = (volatile uint8_t *) PORT3_TX;
*pb = byte;
}
Does not init pb before you test it.
Code: Select all
void _outbyte(uint8_t c) {
volatile uint8_t *pb;
uint8_t byte;
pb = (volatile uint8_t *) PORT3_SCTRL; //<-------------Init Port before checking its Status.
byte = c;
/* wait for RRDY high */
while(!(*pb & 0x02)) pb = (volatile uint8_t *) PORT3_SCTRL;
//Do you ever get to this point here?
pb = (volatile uint8_t *) PORT3_TX;
*pb = byte;
}
If you still have issues them please email me your code and I will have a look and try to get it working for you.
Update:
Sorry! I have forgotten to state and omitted that in my little Demo but the Port3-Control Port also needs to be configured for directions - let me get back to you on that as I need to boot my main machine but nothing will work without the CTRL being set - sorry!
For now set everything to Output and DO NOT try to transmit anything from the PC to the MD so disconnect the MD_Rx pin for now.
#define PORT3_SCTRL 0xA1000D
volatile uint8_t * gpb_p3ctrl=NULL;
gpb_p3ctrl = (volatile uint8_t *) PORT3_CTRL; //(!) call this in your init Function but make sure it is some kind of global or ensure that the scope is within the init and usage and never changes once initialised.
*gpb_p3ctrl =0x7F; //That will get you: Port 3: TH-Int:OFF, PC6..PC0: OUTPUT.
Sorry! That should now get you MD_Tx working
Cheers,
Minty.