Lpc11c24 uart

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lpc11c24 uart

1,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Mon Feb 18 04:03:01 MST 2013
Hi,
I'm not-so-advanced in this kind of programming, and I've stumbled upon a minor problem.

I have to write a code for LPC11C24 to work with CO2 sensor using MODBUS protocol. No interrupts, just a simple write read sequence. I've got UART set correctly (done it before). What I need is to send a sequence, eg. {0xFE, 0x00,...} and read similar sequence back. I've tried to use something I've done before

void uart_send_byte(const uint8_t byte)
{
  while(!(LPC_UART->LSR & 0x20));
  LPC_UART->THR = byte;
}


for each byte of the sequence, but then it looks like there's nothing to receive. The thing is I don't know whether I messed up the sending, or receiving as I don't really know how to print output in console... This may sound like a noobish problem, and in fact it kind of is, but any help would be deeply appreciated...
0 Kudos
35 Replies

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 18:17:15 MST 2013
That's one of the cleverest things I've seen since MSWord autoback up :)

You have no idea how grateful I am for your help- right now I can say I'm finished - got the communication running, there's proper readout on pc, everything is ok. Not ideal certainly, still got a printf() floating inside the code, getting rid of it messes up the project, but it could be worse :)

Thanks once again for everything :)
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 09 17:34:05 MST 2013

Quote: urb4nm
No idea what happened...



Obviously you are ruining your own project ;)

Time to learn how to use History :)

http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2FgettingStarted%2Fqs-...
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 17:14:16 MST 2013
Already tried that, but I think something went wrong with my project... The only way I can run it now, is debugging it with a printf(); uncommented. If I try to flash it with debug build I get some strange info on the way ("assuming 12MHz Clock", when while debuging it reads 48MHz). I changed semihosting options, only result it's it now doesn't send anything to console... No idea what happened...
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 09 16:51:11 MST 2013
Enable 'Vector catch' and switch to ISP ;)

http://www.support.code-red-tech.com/CodeRedWiki/DebugAccessChip

Video: http://youtu.be/chFv1EiZcYo
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 16:14:32 MST 2013
I almost had finished, but then it all crashed... Now I can't flash it correctly, or even run debugging on my project, because I get

file load failure.WT:41: Vectors still have ereased values

What's going on?
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 14:44:11 MST 2013
float temperature = 1234.56;    //melting iron
[COLOR=Red]char temperature_string[33];[/COLOR]    //recommended string length

int main(void)
{
 volatile static int i = 0 ;
 while(1)
 {
  i++ ;
  itoa((int)(temperature*100),&temperature_string[0],10);//convert with decimals
 }
 return 0 ;
}


OK, I see, but what are the loop and increment for? Or was that just problem-specific answer?
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 09 14:12:34 MST 2013
You can't cast integer to string ;)

Probably you want to transmit your integer as ASCII, so you have to convert your integer to a string and transmit this string ;)

Itoa sample: #2 of http://knowledgebase.nxp.com/showthread.php?t=3263 :)
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 13:54:33 MST 2013
Ok, thanks, I think I can go somewhere from here

@Edit

Well, I'm at the point of giving up, but I got one last thing to do, and I can push myself to think a little longer... Is there a way, to cast [B]int[/B] to string, and push it through UART via
void UARTSend(uint8_t *BufferPtr, uint32_t Length)
I did send an already declared string, and it went through without any problem, but whatever i've tried (sprintf, itoa) sends the code flying throug some HardFault Handler.. It might be stupid question,but I'm so confused now, that HelloWorld would be a struggle, and i just want to finish that one last thing...
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 12:37:54 MST 2013
Ok, thanks, I think I can go somewhere from here :)
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 09 12:29:47 MST 2013

Quote: urb4nm
Well... I don't think I understand that, to be honest... ;)



Then read again

CHAPTER 1: What is a pointer? http://pw1.netcom.com/~tjensen/ptr/ch1x.htm

and

CHAPTER 2: Pointer types and Arrays http://pw1.netcom.com/~tjensen/ptr/ch2x.htm

Download it from http://home.earthlink.net/~momotuk/pointers.pdf

Quote: urb4nm

When I try to send that to pc it gets stripped, so from
0xFE, 0x04, 0x00, 0x03, 0x00, 0x01, 0xD5, 0xC5
I get
{FF}uq<0x04><0x00><0x03><0x00><0x01>

I don't know what is wrong...



It's either your hardware or UART settings of PC :eek: So scope your signal :)
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 12:17:08 MST 2013

Quote: Zero
I see, so your sample #22 is wrong, #24 is working correct :)



Well... I don't think I understand that, to be honest... ;)

When I try to send that to pc it gets stripped, so from
0xFE, 0x04, 0x00, 0x03, 0x00, 0x01, 0xD5, 0xC5
I get
{FF}uq<0x04><0x00><0x03><0x00><0x01>

I don't know what is wrong...
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 09 11:38:54 MST 2013
I see, so your sample #22 is wrong, #24 is working correct :)
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 11:20:30 MST 2013
Well, of course there is, I made that up for the sake of explanation, without checking it first What I really have is:


volatile uint8_t CO2_ReadSeq[8] = {0xFE, 0x04, 0x00, 0x03, 0x00, 0x01, 0xD5, 0xC5};
volatile int CO2_ReadSeq_Lenght = sizeof(CO2_ReadSeq);

LPC_UART->IER = IER_THRE | IER_RLS;
 UARTSend((uint8_t *)CO2_ReadSeq,CO2_ReadSeq_Lenght);
LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR;
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 09 10:48:55 MST 2013

Quote: urb4nm

           UARTSend([COLOR=Red](uint8_t *)CO2_xxx[/COLOR],CO2_xxxx);



:confused:

No Warning here :confused:;):eek:
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Sat Mar 09 10:31:41 MST 2013
Once again, I've come across another problem:

I've established connection to C02 sensor through UART, everything works smoothly; I've added  DG409 mux, to switch between sensor and PC, to feed pc with results from sensor. The problem starts with sending data do PC - everything I receive with Hercules is "uq-some rubbish" Whatever i try to send (char, byte, so on) gives mi that constant uq(<75><71>) and I'm sitting here puzzled what's wrong with that. I'm using the same functions as to communicate with sensor...

uint8_t CO2_xxx = 0xA0;
int CO2_xxxx = sizeof(CO2_xxx);
LPC_UART->IER = IER_THRE | IER_RLS;
           UARTSend((uint8_t *)CO2_xxx,CO2_xxxx);
      LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR;
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Thu Feb 21 16:29:38 MST 2013
Yeah, that looks like it :) Thanks once again :)
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Feb 21 15:28:00 MST 2013
Are you trying to debug a library function (=  compiled without debug information) ;) That's usually the cause for this message :)
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Thu Feb 21 15:00:40 MST 2013
Yes, but I tried the thing from #2 of the same topic, and succeeded, I think...

Why is that sometimes I run debugging I get some errors like:
No source available for  __sys_seek() at 0x28b6
No source available for "malloc() at 0x28be" 

And so on?
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Feb 21 13:49:43 MST 2013
Did you read #5 of http://knowledgebase.nxp.com/showthread.php?t=1684 already :confused:
0 Kudos

1,084 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by urb4nm on Thu Feb 21 13:39:42 MST 2013
It seems that I can't include [B]timer32.h[/B] to my project.
I've added [B]#include timer32.h[/B], added [B]#define CONFIG_ENABLE_DRIVER_TIMER32 1[/B], and I still can't call init_timer() and so on. [B]timer32.h[/B] is grayed out/crossed out under ./myproject/driver tree. Is there something I've missed?
0 Kudos