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.
Related
I am trying to move header information into C code without actually writing code. Here's and example of a header that defines how many ADCs that are in a system:
//example definition
#define CONF_USEADC2 6 /*ADC2 on SPI2*/
#define CONF_USEADC3 7 /*ADC3 on SPI4*/
Depending on certain conditions, this hardware will be present or not, and for that reason, there's a byte with the data that tells you if there's the ADCs just so you know how many are in the system (there's a bus constraint so your data is slower if you have 2 ADCs on). I have between 1 and 24 ADCs on a JDEC bus. The code that creates the bits currently looks like the following:
#ifdef CONF_USEADC2
uc_tmp = uc_tmp | (1 << CONF_USEADC2);
#endif
#ifdef CONF_USEADC3
uc_tmp = uc_tmp | (1 << CONF_USEADC3);
#endif
Which bit is set is based on the value of definition, and one can see how this quickly could become a mess. There are many of these definitions in reality which is making things a total mess.
Is there some smart way with MACROs to create method where one could just pass something like CONF_USEADC2 to a macro and if it's defined it sets the bit and if it is not, it just ignores it? In this way, I could have macro(CONF_USEADC2) which would replace that code above to help with readability.
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);
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.
I am programming an µC in C, and for programming I have to use a serial connection. Using this is quite easy, I just have to store the values (e.g. 10011000) I want to send as ints, and then convert them for sending into binary and send them one after another. But now some command bytes should look like XXXX1001, i.e. they contain some bits which are not set. But after the transmission size is fixed to one byte per cycle, I have to fill them up somehow. Furthermore, how can I store them? Does is simply mean that these bits are neglected, and I can set them either to 1 or to 0?
Assuming XXXX1001 is value for a control register to do some settings then XXXX means dont care here.You can set them to any value.
But beware,the same register can have different settings based on upper nibble.If so make sure you are setting them correctly.
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.