3174 views|3 replies

2870

Posts

4

Resources
The OP
 

How to build a Keil project using the LPC8xx ROM? [Copy link]

I recently made a board using the lpc824 chip. Both GPIO and UART can be adjusted smoothly, but the sensor in the project is an IIC interface. I downloaded two projects, lpcopen_3_02_keil_iar_nxp_lpcxpresso_824 and LPC824_Example_Code_Bundle_Keil_r1.0. I2C0 is the same as the development board, so I want to use the Example_I2C_MasterSlave program in the LPC824_Example_Code_Bundle_Keil_r1.0 project.
  1. WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_IDLE); LPC_I2C0->MSTDAT = (Self_Slave_address<<1) | 0; LPC_I2C0->MSTCTL = CTL_MSTSTART; WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_TX); LPC_I2C0->MS TDAT = 0xFE; LPC_I2C0->MSTCTL = CTL_MSTCONTINUE; WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_TX); LPC_I2C0->MSTCTL = CTL_MSTSTOP; WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_IDLE); LPC_I2C0->MSTDAT = (Self_Slave_address<<1) | 0; LPC_I2C0->MSTCTL = CTL_MSTSTART; WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_TX); LPC_I2C0->MSTDAT = 0xE7; LPC_I2C0->MSTCTL = CTL_MSTCONTINUE; WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_TX); LPC_I2C0->MSTCTL = CTL_MSTSTOP; LEDs_Off(RED); //Execution is stuck here??? WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_IDLE); LPC_I2C0->MSTDAT = (Self_Slave_address<<1) | 1; LPC_I2C0->MSTCTL = CTL_MSTSTART; WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_RX);
复制代码
As long as it is a read operation, it will die
  1. ]void WaitI2CMasterState(LPC_I2C_TypeDef * ptr_LPC_I2C, uint32_t state) { while(!(ptr_LPC_I2C->STAT & STAT_MSTPEND)); // Wait for MSTPENDING bit set in STAT register if((ptr_LPC_I2C->STAT & MASTER_STATE_MASK) != state) { // If master state mismatch ... LEDs_Off(G REEN); LEDs_On(RED); while(1); // die here and debug the problem } return; // If no mismatch, return }
复制代码
Someone asked this question in the official forum, but there is no answer! So I used the IIC routine in lpcopen_3_02_keil_iar_nxp_lpcxpresso_824, but the result was even worse! As long as the program is executed, SWD can see the device, but the invalid rom table error occurs during programming. Every time, the ISP is used to start the board. I can't find any reason. There is really no way now. I hope an expert can help me!



This post is from NXP MCU

Latest reply

Don't use the library, use the register operation to see where the card is. If you don't understand the meaning of the library code, you definitely don't know what the reason is. I basically don't use the library, spend some time looking at the registers  Details Published on 2019-4-13 12:23
 

2870

Posts

4

Resources
2
 
  1. LPC_I2C0->MSTDAT = 0xE7; LPC_I2C0->MSTCTL = CTL_MSTCONTINUE; WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_TX); LPC_I2C0->MSTCTL = CTL_MSTSTOP;
复制代码
In the code, WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_TX);//Who suspends the device after issuing a read operation? There is also a function called WaitI2CSlaveState(LPC_I2C_TypeDef * ptr_LPC_I2C, uint32_t state). Shouldn't it be this function?
This post is from NXP MCU
 
 
 

1131

Posts

17

Resources
3
 
Don't use the library, use the register operation to see where the card is. If you don't understand the meaning of the library code, you definitely don't know what the reason is. I basically don't use the library, spend some time looking at the registers
This post is from NXP MCU

Comments

Thank you for your reply! The reason was found out, mainly because it died in the interrupt. So I added the following code in the interrupt. Although it "did not die", I still could not operate the sensor. optIndex is the sequence number of my operation, which is used to mark which operation step was executed. I connected the sensor and removed it.  Details Published on 2019-4-13 19:12
 
 
 

2870

Posts

4

Resources
4
 
fxyc87 posted on 2019-4-13 12:23 Don't use the library, use the register operation to see where the card is. If you don't understand the meaning of the library code, you definitely don't know the reason. I basically don't use the library, spend a little...
Thank you for your reply! The reason was found out, mainly because of the interrupt. So add the following code in the interrupt.
  1. sprintf(dis_data,"STAT:%c %x %x %x %x#\n\r",optIndex,LPC_I2C0->STAT,LPC_I2C0->SLVDAT,LPC_I2C0->MSTDAT,LPC_I2C0->MONRXDAT);
复制代码
Although it is "not dead", I still cannot operate the sensor. optIndex is the sequence number of my operation, which is used to mark which operation step is executed. I connect and remove the sensor, and the program can obtain "data". -------Connect the sensor----------- STAT:A db100 80 40 481# //Slave device hangs up. At least one of the four slave addresses matches the hardware? STAT:B df300 fe 7f 180# //Slave device suspends slave address reception STAT:C db100 80 40 fe# //Slave device suspends STAT:D df300 e3 71 180# //Slave device suspends STAT:E db100 81 40 e3# //Slave device suspends STAT:E df500 81 81 181# //Slave device suspends-------Remove the sensor------------- STAT:A 43100 80 40 0# STAT:B 57300 fe 7f 180# STAT:C db100 80 40 fe# //Slave device suspends At least one of the four slave addresses matches the hardware? STAT:D df300 e3 71 180# //Slave device suspends slave address reception STAT:E db100 81 40 e3# STAT:E df500 81 81 181# From the data, we can know that a second interrupt is executed when performing the read operation, E, E proves that there is "data input" after the output address. I took off all the sensors, where did the data come from! I don't know if anyone has done I2C programming, please give me some advice. Because I only have one I2C sensor, and I bought an I2C OLED screen but it has not arrived, so I can't prove whether the sensor is broken.
This post is from NXP MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list