Hello all,
I'm working on a basic RS-232 receiver to work with the basic FTDI usb converter. I've got it to work but I've run into a weird problem. It works perfectly for single reads, but if I have it read a bunch of times(not in a row, maybe a few millisecond gap between data being sent) it will just stop working. The weird part about this is it seems to be random. The number of reads until it breaks is probably 50-100. And the state the it breaks in is seemingly random.
*code below for reference.
It's kind of hard to describe what I mean by it breaking. It's like it just becomes completely unresponsive. Data comes into the RX line but it never responds. So you would think it's just stuck in some state, but I fairly thoroughly tested to see what state it was getting stuck in but I can't tell. What I did was make an test output and have it assert when it's in that state. This gave me completely random results. It was almost like, if I asserted the test output in a state, it would never fail in that state. I could never get it to consistently fail on a state. Then to make things weirder if if I have it assert in some states it will actually start working completely. But then other states it won't work. Which doesn't really make sense. This test output isn't connected to anything, it just goes high or low and I look at it on a logic analyzer.
I know I've given a lot of information but I guess that's because it's very random and I can't see the pattern here. For example, if I remove a state that essentially has it wait for the stop bit to pass, it will actually work. The problem with this is that depending on what the last data bit is, it might confuse it for the start bit and start an invalid read. But I can't see why this is, it all seems random.
Ok here's the code. There's a major design flaw so I'm going to rewrite it but I'm just very curious about what would cause this. Also I simulated and it does not exhibit this problem.
This code is the RS-232 receiver. It works by checking the RX line for the start bit every cycle, so that it doesn't miss it. Then the rest is just handshaking to give the data to the module that wants it. It's not complete because I ran into this problem.
http://pastebin.com/Hrgkjb2rFor reference the module that is driving this one is here. It pretty much just takes the data from it then outputs it to some LEDs.
http://pastebin.com/dCeREk3vAny suggestions or thought would be great. I'm very curious about what could cause this because with my limited understanding I don't know of anything that could.