Enable port RA0 as input and retrieve value LDR from led - c

I'm using the picdem 18F4550 with microchip v8.63 with the C18 compiler.
I will enable PortA to set as input, I will connect a LDR on port RA0.
Which is as following (I think)
TRISAbits.TRISA0 = 1; <= set RA0 as input
Now I want the value of the LDR (voltage/value if a led is on), can I say:
int colorLed = PortAbits.RA0;
And now in the variable of type int there is the value/voltage of my Led.
Correct me if i'm wrong.

It sounds like you want to measure an analogue voltage, in which case you will need to use the pin as AN0, rather than RA0. You should read section 21 of the datasheet, but in summary, you will need to configure the A-D converter using registers ADCON0, ADCON1 and ADCON2, and read the result that's present on ADRESH:ADRESL.
Note that you could potentially read the LDR using a digital input, but you will be unable to calibrate it. Using the analogue input is slightly more complicated, but much more flexible.

PORTA can function as a digital input or analog input, by default.
To use an LDR you most likely need to to configure the PIN as analog input.
HOwever it still depends on what you want to do. Maybe you should give a bit mroe details as to your project.
check this link for the PIC18F4550 datasheet
You can only find more detailed resources on the PIC184550 here
again, you might want to give more details on your application so we can help you better.

Related

Usage of Xilinix Built in UART Function to Bitmask certain Value

I am using the Xilinx uartps data sheet in order to write functions to disable and enable Flow Control For UART. I found the appropriate bitmask defined in the data sheet, however I am not sure which built in function I should call with this mask in order to pass this bit mask to.
I thought initially it may be this function,
However upon closer inspection, it takes a u16 as an argument and the bitmask I want to use is a u20. Anyone familiar with this library, what function do I call with the bit mask in order enable flow control
Here is a link to the datasheet as well.
https://xilinx.github.io/embeddedsw.github.io/uartps/doc/html/api/group__uartps__v3__11.html#gad74cdb596f414bee06ebd9159f496cef
You are correct in what you are using. The masks have a hex "0" more than the 16bits they should represent, but if you look at the options, this bit is never used.
Configuration options
#define XUARTPS_OPTION_SET_BREAK 0x0080U
These constants specify the options that may be set or retrieved with the driver, each is a unique bit mask such that multiple options may be specified.
#define XUARTPS_OPTION_STOP_BREAK 0x0040U
Stops break transmission.
#define XUARTPS_OPTION_RESET_TMOUT 0x0020U
Reset the receive timeout.
#define XUARTPS_OPTION_RESET_TX 0x0010U
Reset the transmitter.
#define XUARTPS_OPTION_RESET_RX 0x0008U
Reset the receiver.
#define XUARTPS_OPTION_ASSERT_RTS 0x0004U
Assert the RTS bit.
#define XUARTPS_OPTION_ASSERT_DTR 0x0002U
Assert the DTR bit.
#define XUARTPS_OPTION_SET_FCM 0x0001U
Turn on flow control mode.
This means that you might get a warning when using such flags, but you'll get the result you want anyway.

Access of register STM32 CAN communication

can you help me to figure out what this line do :
while (hcan->Instance->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
It is the common way to check flags or more precisliy - if bit is set in some register. In this particular example:
INAK: Initialization acknowledge This bit is set by hardware and
indicates to the software that the CAN hardware is now in
initialization mode.
So you are basically wait in the infinite loop until CAN enter initialization mode.
BTW. I think you have way to much structures in your CAN configuration. If you use CMSIS macros package, it should look like this:
while((CAN->MSR & CAN_MSR_INAK) == 0);

Serial Instruction bit not clear

I've bought a cheap Wingstar 144x32 LCD, because it would be nice to have it plugged onto my NodeMCU for showing some information.
What I wasn't expecting, was that nowhere on the internet could I find a working library for that LCD. So I thought I'd write my own.
I spent several hours reading through the datasheet, trying to figure out how the SPI instructions were passed to the LCD. I then discovered that on some other site there was an example code for the Arduino (which is faaar too long to understand properly) and one for the ATMega, which is short and way easier to understand.
I opened the files and saw that the interfacing is quite "simple", if I can say so. It looks like this:
write_command(0x38); // function set -- 8 bit mode, basic instruction set
write_command(0x0F); // display control -- cursor on, blinking
write_command(0x01); // display clear
write_command(0x06); // entry mode -- cursor moves right, address counter increased by 1
write_command isn't that important to mention here, because it only sends the command through SPI:
void write_command(unsigned char command) {
SPI_WriteByte(0xF8); // send command header
SPI_WriteByte(command&0xF0); // send high nibble
_delay_us(250);
SPI_WriteByte((command<<4)&0xF0); // send low nibble
_delay_us(750);
}
Despite not understanding what the &0xF0 or the <<4)&0xF0 do, I moved on.
I picked randomly the "function set" instruction and converted it to binary text to see if it's doing that what I'm thinking.
0x38 = 0000 0000 0011 1000
Excluding the first 8 characters (It wouldn't make sense with those), I'm left with 00111000, which would make sense putting it there:
Because: DL=1 (8bit interface selected, like the comment in the code for the ATMega - great) and RE=0 (Basic instruction, like in the comment in the code for the ATMega - great!).
But now the real question: What are those "X" in the instruction codes? I already searched the entire datasheet and found nothing about those "X"-es. Why are they inconsistent? What are they supposed to be doing there?
I hope I didn't mess it up too bad.
Any help is highly appreciated.
They are 'don't care' bits. On read, they contain no useful information. On write, they do nothing.

how to change MPU9150 sensitivity?

I want to know what sensitivity I am working with on an mpu 9150 (+ Raspberry PI).
this is the library I am using: linux-mpu9150
mpu 9150 page
I want the accelerometer to have more sensitivity(so I must set it to 2+/-g ?!?).
When I count the steps, there aren't enough...I take 10 steps, I count 3-5 steps with matlab (with peakfinds or counting zero crossing)
Example:
Accelerometer at my foot, or at my shin (make similar output)
The github link you posted contains a calibration section, they suggest using imucal here:
https://github.com/mrbichel/linux-mpu9150/blob/master/README.md
Good luck.

How to relocate vector table and change starting addressin cortexm3 using uvision(Keil)?

I'm using a STM32F107 cortex m3 microcontroller. I'm using the Keil uvision IDE for the project. I have an application which is running properly at the starting location i.e 0x0800 0000. If I change the starting location to 0x0800 4000 the application is not working properly. I made changes to the vector table location using this function as such:
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8004000)
i.e changed SCB->VTOR = 0x8004000 to this location.
But even after doing this interrupt is not happening. Should I do anything more to make this project work?
You should not use NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8004000), use NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000). The second argument is the "offset", not the absolute address.
Add the below instruction just after the HAL_Init();
SCB->VTOR = (FLASH_BASE | 0x4000);
You also need to update the interrupt vector address in the STM32F1xc_flash.icf file as below.
define symbol ICFEDIT_intvec_start = 0x08004000;
I did this for my STM32L496, and it was important to set the new vector table before calling HAL_Init(), because it calls HAL_MspInit(), which may use the SysTick to measure timeouts while setting up some peripherals.

Resources