Menu
  • HOME
  • TAGS

Configure PIC18f2455 to use RS232

Tag: pic,usart

I'm using USART of PIC18f2455 with RS232 and having some trouble to configure it.

I'm using a 24 MHz Crystal Oscillator. The PLL is enabled with prescaler of 6 (to set 4MHz at input) and gives a fixed 96 MHz at output. The postscaler is set to 6 giving at end a 16MHz to Microcontroller clock.

With this clock I set the SPBRG of OpenUSART function to 25 for a Baud Rate of 9600 .

This is my USART config:

#pragma config PLLDIV = 6, CPUDIV = OSC4_PLL6, USBDIV = 2, FOSC = HSPLL_HS OpenUSART(USART_TX_INT_ON & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 25);

It is getting stuck at OpenUSART function...

Best How To :

For a 16MHz microcontroller clock change USART_BRGH_LOW, 25 to USART_BRGH_HIGH, 103 which will result in 9,615.38 baud (9600 -0.2%). Why not use CPUDIV = OSC1_PLL2 to give you a 48 MHz clock? You'd then use USART_BRGH_LOW, 77.

connect (RS232 to USB )cable on linux

ubuntu-14.04,microcontroller,pic

Ok. 1. JDM programmer uses the voltage from a true serial port to extract the VPP and VDD required to program any PIC controller. The USB2RS232 adapter you purchased will never work on Win or Linux no matter what you try. If you are the unlucky user of a laptop...

UART pic18 to pic18

c,pic,uart,mikroc

I had once this problem, and the fact was that the character was not a unsigned char. so try to cast it. ... while (1) { if (UART2_Data_Ready()) { // If data is received, uart_rdi = UART2_Read(); // read the received data, uart_rd = uart_rdi; LCD_Out(1,1, (unsigned char) uart_rd); ......

Generic Microcontroller Delay Function

c,delay,pic,mplab

This is referred to as busy waiting, a concept that just burns some CPU cycles thus "waiting" by keeping the CPU "busy" doing empty loops. You don't need to reset the function, it will do the same if called repeatedly. If you call it with N=3, it will repeat the...

Serial received data not recognised

python,networking,raspberry-pi,pic

There is nothing wrong in your code. If you write PIC program correctly then the problem is coming from the proper termination resistors of max485.connect twisted pair cable ground with proper resistance.

How many sensors will work at a time in an Arduino for Home automation?

arduino,microcontroller,sensor,pic,home-automation

If the sensors use I2C then the limit is 128 devices on the bus, but they each have to have a unique address which are sometimes "hard-coded" on the device by the manufacturer. The Arduino Wired library is used to read/write I2C and it only takes two pins. I2C is...

ADC single conversion on STM32

c,serial-port,stm32,adc,usart

Problem solved! It's my fault to disable external trigger. Instead of using: ADC_InitStructure.ADC_ExternalTrigConv = DISABLE; It shoud be like this: ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; What a silly!...

Home automation using arduino and Pic microcontroller [closed]

automation,arduino,microcontroller,pic,home-automation

Buidling a system like this is certainly possible. The better way to get to a good solution is to define requirements first and then to think about a solution (e.g. which processor to use). You are not very specific which number of sensors you want to use and where they...

String concatenate error with malloc dynamic memory allocation

c,string,pic,microchip,pic32

Your first call to my_strcat has undefined behavior because buf was not initialized before. Precisely this line is the problem new_str = malloc(strlen(str1)+strlen(str2)+1); strlen(str1) where str1 is uninitialized. Suggestion, use realloc char *my_strcat(char *str1, const char *str2) { char *new_str; size_t length; size_t str1length; if (str2 == NULL) return str1;...

I cannot get the led to blink 6 times, then terminate the program in C

c,pic,terminate

This code successfully called the sleep function and exited the infinite loop (Thanks to @francis): #include <htc.h> #include <pic16f877.h> #define _XTAL_FREQ 4e6 #define SLEEP() asm("sleep") int main(void){ int count = 0; int max_count = 6; TRISD = 0xBF; while(count<max_count){ count++; PORTD = 0x40; __delay_ms(500); PORTD = 0x00; __delay_ms(500); } SLEEP();...

Why python prints a single multi-digit numbers in multiple lines?

python,python-2.7,avr,usart

I'll try to explain what happens: On the µC side, you transfer a value over a serial line. You have to decide in which format this happens and to make the receiver use the same format. You have decided to use ASCII. So the device converts each value into its...

Led on/off using PIC 16f777a

embedded,pic,led,hi-tech-c

I think is a "too short" loop. Using a double while to catch an input causes that both IF can be valid thousand of times until you release the pushbutton. A suggest you to manage it on the release of button, that means you trigger the push of button and...

Direct memory access RX for the STM32L1

c,microcontroller,stm32,dma,usart

In the end, this is the configuration that I used to get it working. const int datasize = 32; char buffer[32]; static void dma_setup(void) { dma_channel_reset(DMA1, DMA_CHANNEL6); nvic_enable_irq(NVIC_DMA1_CHANNEL6_IRQ); // USART2_DR (not USART2_BASE) is where the data will be received dma_set_peripheral_address(DMA1, DMA_CHANNEL6, (uint32_t) &USART2_DR); dma_set_read_from_peripheral(DMA1, DMA_CHANNEL6); // should be 8 bit...

reading 2 analogue pins on the PIC

embedded,pic

Change the ADC mux value from 0 to 1 in ADCON0 (bits: CHS0..CHS3) register, wait some time (some us to fill ADC sample capacitor) and call again GETVALUE function.

Configure PIC18f2455 to use RS232

pic,usart

For a 16MHz microcontroller clock change USART_BRGH_LOW, 25 to USART_BRGH_HIGH, 103 which will result in 9,615.38 baud (9600 -0.2%). Why not use CPUDIV = OSC1_PLL2 to give you a 48 MHz clock? You'd then use USART_BRGH_LOW, 77.

PIC in C - creating own keypad scan routine using RC0-3

c,pic,mikroc

In the previous question you linked, the "1,2,4,5" refer to the keypad legends which might be anything and often bear no relation to the bit values you receive back. You write a "1" bit to each output (row) in turn (or a "0" for inverted logic) and look for high...

dsPic Receive 11byte usart string

microchip,usart

jolati had a good point about the end value beeing too low to get 11 bytes but I must add that you have to wait for your other bytes to become available before you read them. In your example; char inBytes[11]; int i; unsigned char temp; while (!U1STAbits.URXDA ); //Wait...

Unable to check received value on serial port in Matlab

matlab,serial-port,char,usart

You can use deblank (removes all whitespace characters) or strtrim (removes only leading and trailing whitespace) to get rid of unwanted characters: a = sprintf('.\r\n'); disp(a) . strcmp(a,'.') ans = 0 strcmp(strtrim(a),'.') ans = 1 Also, you're using fscanf to retrieve data from the serial port, try using fgetl instead....

MicroC rs-485, pic16f887 String sending problems

c,pic,microchip,rs485,microc

char dat[9]; defines an array of 9 bytes, so dat[7] = "MY STRING"; will only store a truncated address not the actual string. memcpy can be used to copy strings from one buffer to another. see: http://www.cplusplus.com/reference/cstring/memcpy/ dat[7]=="MY STRING" will not work as your comparing the 2 byte address of...

Building a drone. Using microcontroller

microcontroller,pic

The first place I would suggest looking is Jameco.com. They have an excellent and perpetually up-to-date selection of components; however, you should note that manual production of a device is usually much more expensive than when using a few mass-produced components (not that I'm discouraging you). While your question is...

Lantronix XPORT - TCP/IP tunnel to send HTTP POST requests

http,microcontroller,wireshark,pic,ethernet

I have finally found the solution! After some (logical) thinking I found that it would be the problem of the XPORT. But what could be the problem? I disabled all features of which I thought that might interfere (even though I thought this would be unlogical to cause this kind...

Making a delay in C with 20MHz crystal(beginner level)

c,delay,interrupt,pic

No, since the code in main() never actually waits, it won't implement a delay. Assuming the interrupt and timer logic is properly set up, you're still going to need to loop: delay = 0; TMR0 = 155; /* Start timer. */ while(delay < 4) ; /* Do nothing */ /*...

STM32F407 UART gives garbage on terminal

arm,stm32,stm32f4discovery,baud-rate,usart

USART1 on this board (TX pin) has capacitor which collides with traffic. It is mentioned on ST forums.

How to configure 8051 pins as input/output?

input,output,microcontroller,pic,8051

Actually, there is nothing to set a standard 8051 pin as an input; all pins are always bidirectional. However, if you write a '0' to a pin, it turns the open-drain driver ON and there is no way that anything external can ever force it to anything other than '0'...

Why doesn't the LED light up?

assembly,microcontroller,pic,microchip,led

The least significant bit of TRISC indicates whether RC0 is an input or an output. In your code you are setting it to 1, which is an input. The mnemonic is 1 looks like an I (input) and 0 looks like an O (output). Also with this type of problem...

how to show UART received data (on PIN 10, RX) of Raspberry pi on Tkinter Window

python-2.7,raspberry-pi,pic,uart

import serial, time, struct ser = serial.Serial("/dev/ttyAMA0", 9600) while True: count = 0 AValue = [] for ch in ser.read(): if ch == "\n": AValue = [] time.sleep(0.1) while count < 4: for ch in ser.read(): AValue.append(ch) count += 1 im using this code to recive four bytes of code...

PIC16F887 PORT won't work with XC8 C compiler

c,embedded,pic,microchip,xc8

I think the problem is that those specific pins are also Analog Inputs for the ADC Module, you have to configure them to be digital I/O to use them. Try setting ANSEL = 0x00 at the beginning of your program. You can see in the datasheet that the default value...

PIC Assembly: Configure Timer1 for particular time interval

assembly,pic

I understood that timer increments a value in its register according to a prescaler until overflow occcurs in which case it will send an interrupt. This is partially correct. The value is incremented based on the selected clock input and the prescalar. The prescalar simply divides the clock input...

reading analogue PIC port

embedded,pic

What is your clock mode ? Looking at the datasheet, section Clock Mode or p176, configuration bits, at the CONFIG register, you may choose between different clock mode. http://ww1.microchip.com/downloads/en/DeviceDoc/41262A.pdf You may be using the INTOSC mode (CONFIG.FOSC2-0=101). "CLKOUT function on RA4/AN3/T1G/OSC2/CLKOUT pin, I/O function on RA5/T1CKI/OSC1/CLKIN". You could use the...

PIC 16F1788 reading voltages

c,pic,microprocessors

You do not need to reconfigure the pin inside the loop. Start-up configuration should occur at the beginning of main. ADC_Read does not return a floating-point value; you need to convert it yourself. For a 12-bit ADC, you can have const float conversion_factor = 6.5f / ( ( 1 <<...

Pack numbers into a bitset (python,bitwise operations)

python,bit-manipulation,bit,pic

Your shifts are wrong. You are shifting by the index of the top-most bit, which isn't right. You must shift by the index of the lowermost (rightmost) bit in each field. So it should be: def fileRegOp(opcode, d, f): return (opcode << 8) | (d << 7) | f This...

How to achive higher PWM frequency?

embedded,microcontroller,pic,microchip,pwm

For a start, you have the parameters to the functions reversed. Open() takes a char value less than 256, and Set() takes a 10-bit number. That said, you have chosen the largest value (255) which gives the lowest frequency. As the datasheet explains, the Open() function takes a value for...

PIC 32 TTL communication

microcontroller,pic,mplab,ttl,pic32

Basically following things are important while setting up UART communication UART Baud rate UART pin initialization (TRIS bits in PIC) How many Data bits (7 or 8) How many Stop bits (1 or 1.5 or 2) Parity (No or Odd or Even) I can see all these things initialized in...

Reading pic input on PIC12LF1552

c,pic,mplab

According to the datasheet http://www.alldatasheet.com/datasheet-pdf/pdf/504825/MICROCHIP/PIC12LF1552.html, on page 93 about the ANSELA register : "The ANSELA bits default to the Analog mode after Reset. To use any pins as digital general purpose or peripheral inputs, the corresponding ANSEL bits must be initialized to ‘0’ by user software." If you don't plan...

Communicating with custom made USB device on android

android,pic,cdc,usb-otg

Thanks to the comment from Chris Stratton, I was able to find the problem in my code. I was sending 0x04 (Ctrl-D) instead of 0x34 (4) The controlTransfer seems to be unnecessary, I'm using PIC16F1454 with built in USB functionality The receiving buffer was smaller than the reply of the...

PIC Assembly: Decrementing register with 0

assembly,pic

SUBLW will subtract the value in W with the literal regardless of W being zero or not. The result of course will be like W = W - literal; If W = 0 then it's a negation if the type is signed, or a wrap around if it's unsigned. Before:...

C program for a counter

c,counter,pic

You can look at this code: int sw = 0; #define MAX 100 #define gotosleep sleep(10) int main(void) { int num = 0; while(1) { gotosleep; if(sw) num++; else num = 0; if(num == MAX) { //do something printf("Done\n"); num = 0; break; } } return 0; } Go to...

ATmega16 programing-registers mismatchs

c,usart,atmelstudio,atmega16

according to datasheet of ATMEGA16, it is not required to set MSB of UCSRC as its initial value is 1. When you are working with UART you need to make sure that, You are setting proper UBRRL and UBRRH, according to controller clock using formula as below: FOSC/16/BAUD-1 Enable RXEN...

PIC Assembly: ISR for Timer1

assembly,pic

On the PIC16F877A, all interrupts trigger the same ISR stored at 0x04. Therefore, you need something along the lines of: ORG 0x04 GOTO ISR Elsewhere: ISR: BTFSC INTCON, TMR0IF GOTO tmr0_ISR BTFSC PIR1, TMR1IF GOTO tmr1_ISR My syntax might not be correct, it's been a while since I've written PIC16...

Confused with output to console, C / USB CDC / PIC18F2550

c,usb,pic,cdc

You should call putUSBUSART() and CDCTxService() before overwriting output_message Also, CDCTxService() needs to be called frequently, so you have to call it during the delay loop. for int bbb = 0; bbb < 5; bbb++) { sprintf(output_message, "\r\nLooping...\r\n"); putsUSBUSART(output_message); for (delayIndex = 0; delayIndex < 1000; delayIndex++) { __delay_ms(1); if(USBUSARTIsTxTrfReady())...

Is this valid code? extern marked with @ and address, from PIC microcontroller libraries [duplicate]

c,syntax,clang,pic,pic18

however is this standard C or is this a microchip only extension for their compilers? It is not Standard C but it is a common extension used by some C embedded compilers. See my answer here on this specific topic: @ sign in C variable declaration...

STM32F0-Discovery: no tty

linux,stm32,tty,usbserial,usart

The device gets discovered and it's a ST-Link debug interface. The STM32F0308-Discovery does not have a USB UART interface and the ST-Link does not include UART functionality as far as I can see. What you are trying to do appears to be impossible without extra hardware. You would have to...

Can't initialize PWM on dsPIC33F

c,microcontroller,pic,pwm,xc16

I believe you have set up the timer to count from 0 to 181 (P1TPER) and then reset and repeat. But you have set the duty cycle registers to 0x7FFF, which is greater than 181. So I believe the duty cycle value will never be less than the timer value...