CAN на STM32f103c8t6

Все о микроконтроллерах: AVR, PIC, STM8, STM32, Arduino, Altera, Xilinx, все что угодно. Этот раздел для всего что клацает байтиками.
Аватара пользователя
Guddiny
Сообщения: 6

Сообщение Guddiny » 17 авг 2014, 16:46

Всем привет. Может кто поможет, уже который день бьюсь с CAN на STM32f103c8t6.В эмуляторе все работает (Keil), но в железе никак :( (смотрю CAN анализатором и осциллографом) - на выходе с процессора (CAN-TX) висит высокий уровень на на выходе с VP230 - низкий. Программа пока просто должна отправлять посылку. Файлы проекта, схемы и фото прикладываю. Спасибо.
main.c

Код: Выделить всё

#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "misc.h"
#include "stm32f10x_tim.h"

ErrorStatus HSEStartUpStatus;

//*************************************************************************
//RCC Setting
//*************************************************************************
void RCC_Configuration(void){
RCC_DeInit();
    RCC_HSEConfig(RCC_HSE_ON);
      HSEStartUpStatus = RCC_WaitForHSEStartUp();
   
   if (HSEStartUpStatus == SUCCESS)
    {
        /* HCLK = SYSCLK */
        RCC_HCLKConfig(RCC_SYSCLK_Div1);

        /* PCLK2 = HCLK*/
        RCC_PCLK2Config(RCC_HCLK_Div1);

        /* PCLK1 = HCLK*/
        RCC_PCLK1Config(RCC_HCLK_Div1);

        //ADC CLK
        RCC_ADCCLKConfig(RCC_PCLK2_Div2);

        /* PLLCLK = 8MHz * 6 = 24 MHz */
        RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_6);
         
 /* Enable PLL */
        RCC_PLLCmd(ENABLE);

        /* Wait till PLL is ready */
        while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}

        /* Select PLL as system clock source */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

        /* Wait till PLL is used as system clock source */
        while (RCC_GetSYSCLKSource() != 0x08) {}
    }

}
//*************************************************************************
//INTERRUPTS stting
//*************************************************************************
void Interrupt_timer(){

//   TIM_TimeBaseStructInit(&base_timer);
TIM_TimeBaseInitTypeDef base_timer;
  TIM_TimeBaseStructInit(&base_timer);
    base_timer.TIM_Prescaler = 24000 - 1;
      base_timer.TIM_CounterMode = TIM_CounterMode_Up;
    base_timer.TIM_Period = 100;
    TIM_TimeBaseInit(TIM4, &base_timer);
 
    TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
    TIM_Cmd(TIM4, ENABLE);
         __enable_irq();
 NVIC_EnableIRQ(TIM4_IRQn);
   
}

//*************************************************************************
//GLOBAL VARIABLES
//*************************************************************************
GPIO_InitTypeDef GPIO_Set; //variable for Setting gpio
uint32_t u = 0;
uint32_t i = 0;
uint16_t delay_counter=0;
//*************************************************************************
//SYS_TICK & DELAY Settings
//*************************************************************************
void SysTick_Handler(void)
{
   if (delay_counter>0)
   {
      delay_counter--;
   }
}
void delay_ms(uint16_t delay_temp)
{
   delay_counter=delay_temp;

    while(delay_counter);
}
//*************************************************************************
//GPIO Settings
//*************************************************************************
//TX
void GPIO_Setting(void){
GPIO_Set.GPIO_Pin = GPIO_Pin_9;
GPIO_Set.GPIO_Speed = GPIO_Speed_10MHz; //set speed port - 10MHz
GPIO_Set.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOA, &GPIO_Set);
}
//*************************************************************************
//CAN global Settings
//*************************************************************************
void CAN_Setting(){

CAN_InitTypeDef CAN_Set;
   
   CAN_Set.CAN_Prescaler = 6;
   CAN_Set.CAN_Mode = CAN_OperatingMode_Normal;
   CAN_Set.CAN_SJW = CAN_SJW_1tq; //500kbps
   CAN_Set.CAN_BS1 = CAN_BS1_10tq;
   CAN_Set.CAN_BS2 = CAN_BS2_5tq;
   CAN_Set.CAN_TTCM = DISABLE;
   CAN_Set.CAN_ABOM = DISABLE;
   CAN_Set.CAN_AWUM = DISABLE;
   CAN_Set.CAN_NART = DISABLE;
   CAN_Set.CAN_RFLM = DISABLE;
   CAN_Set.CAN_TXFP = DISABLE;
            CAN_Init(CAN1, &CAN_Set);

}


//*************************************************************************
//CAN Tx message Settings
//*************************************************************************
void CAN_TxMSG(void){
CanTxMsg msg;                         
    msg.StdId = 0xA1;
    msg.ExtId = 0x1234;
    msg.IDE = CAN_ID_STD;
    msg.RTR = CAN_RTR_DATA;
    msg.DLC = 8;
    msg.Data[0] = 11;
    msg.Data[1] = 51;
     msg.Data[2] = 52;
     msg.Data[3] = u;
     msg.Data[4] = 54;
     msg.Data[5] = 50;
     msg.Data[6] = 56;
     msg.Data[7] = u;
CAN_Transmit(CAN1, &msg);
   
}

//*************************************************************************
//CAN Rx message Settings
//*************************************************************************

//*************************************************************************
//MAIN
//*************************************************************************

int main()
{
   
   RCC_Configuration();
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);   //
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);    //
   GPIO_PinRemapConfig(GPIO_Remap1_CAN1,ENABLE);      //
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);    //
   GPIO_Setting();
   //SysTick_Config(SystemCoreClock/1000);
   CAN_Setting();
   Interrupt_timer();   
   
while(1){

   // CAN_TxMSG();
   
///   delay_ms(5);
   
   
//u++;
//CAN1 -> RF0R |= CAN_RF0R_RFOM0;
   
   }
}

//*************************************************************************
//INTERRUPTS - 1
//*************************************************************************
void TIM4_IRQHandler(void){

   TIM4->SR &= ~TIM_SR_UIF;
CAN_TxMSG();

      //delay_ms(500);
   u++;
   CAN1 -> RF0R |= CAN_RF0R_RFOM0;
   
}

yaachii
Сообщения: 39981

Сообщение yaachii » 19 апр 2025, 13:27


yaachii
Сообщения: 39981

Сообщение yaachii » 02 май 2025, 13:48

http://audiobookkeeper.ruhttp://cottagenet.ruhttp://eyesvision.ruhttp://eyesvisions.comhttp://factoringfee.ruhttp://filmzones.ruhttp://gadwall.ruhttp://gaffertape.ruhttp://gageboard.ruhttp://gagrule.ruhttp://gallduct.ruhttp://galvanometric.ruhttp://gangforeman.ruhttp://gangwayplatform.ruhttp://garbagechute.ruhttp://gardeningleave.ruhttp://gascautery.ruhttp://gashbucket.ruhttp://gasreturn.ruhttp://gatedsweep.ruhttp://gaugemodel.ruhttp://gaussianfilter.ruhttp://gearpitchdiameter.ru
http://geartreating.ruhttp://generalizedanalysis.ruhttp://generalprovisions.ruhttp://geophysicalprobe.ruhttp://geriatricnurse.ruhttp://getintoaflap.ruhttp://getthebounce.ruhttp://habeascorpus.ruhttp://habituate.ruhttp://hackedbolt.ruhttp://hackworker.ruhttp://hadronicannihilation.ruhttp://haemagglutinin.ruhttp://hailsquall.ruhttp://hairysphere.ruhttp://halforderfringe.ruhttp://halfsiblings.ruhttp://hallofresidence.ruhttp://haltstate.ruhttp://handcoding.ruhttp://handportedhead.ruhttp://handradar.ruhttp://handsfreetelephone.ru
http://hangonpart.ruhttp://haphazardwinding.ruhttp://hardalloyteeth.ruhttp://hardasiron.ruhttp://hardenedconcrete.ruhttp://harmonicinteraction.ruhttp://hartlaubgoose.ruhttp://hatchholddown.ruhttp://haveafinetime.ruhttp://hazardousatmosphere.ruhttp://headregulator.ruhttp://heartofgold.ruhttp://heatageingresistance.ruhttp://heatinggas.ruhttp://heavydutymetalcutting.ruhttp://jacketedwall.ruhttp://japanesecedar.ruhttp://jibtypecrane.ruhttp://jobabandonment.ruhttp://jobstress.ruhttp://jogformation.ruhttp://jointcapsule.ruhttp://jointsealingmaterial.ru
http://journallubricator.ruhttp://juicecatcher.ruhttp://junctionofchannels.ruhttp://justiciablehomicide.ruhttp://juxtapositiontwin.ruhttp://kaposidisease.ruhttp://keepagoodoffing.ruhttp://keepsmthinhand.ruhttp://kentishglory.ruhttp://kerbweight.ruhttp://kerrrotation.ruhttp://keymanassurance.ruhttp://keyserum.ruhttp://kickplate.ruhttp://killthefattedcalf.ruhttp://kilowattsecond.ruhttp://kingweakfish.ruhttp://kinozones.ruhttp://kleinbottle.ruhttp://kneejoint.ruhttp://knifesethouse.ruhttp://knockonatom.ruhttp://knowledgestate.ru
http://kondoferromagnet.ruhttp://labeledgraph.ruhttp://laborracket.ruhttp://labourearnings.ruhttp://labourleasing.ruhttp://laburnumtree.ruhttp://lacingcourse.ruhttp://lacrimalpoint.ruhttp://lactogenicfactor.ruhttp://lacunarycoefficient.ruhttp://ladletreatediron.ruhttp://laggingload.ruhttp://laissezaller.ruhttp://lambdatransition.ruhttp://laminatedmaterial.ruhttp://lammasshoot.ruhttp://lamphouse.ruhttp://lancecorporal.ruhttp://lancingdie.ruhttp://landingdoor.ruhttp://landmarksensor.ruhttp://landreform.ruhttp://landuseratio.ru
http://languagelaboratory.ruhttp://largeheart.ruhttp://lasercalibration.ruhttp://laserlens.ruhttp://laserpulse.ruhttp://laterevent.ruhttp://latrinesergeant.ruhttp://layabout.ruhttp://leadcoating.ruhttp://leadingfirm.ruhttp://learningcurve.ruhttp://leaveword.ruhttp://machinesensible.ruhttp://magneticequator.ruhttp://magnetotelluricfield.ruhttp://mailinghouse.ruhttp://majorconcern.ruhttp://mammasdarling.ruhttp://managerialstaff.ruhttp://manipulatinghand.ruhttp://manualchoke.ruhttp://medinfobooks.ruhttp://mp3lists.ru
http://nameresolution.ruhttp://naphtheneseries.ruhttp://narrowmouthed.ruhttp://nationalcensus.ruhttp://naturalfunctor.ruhttp://navelseed.ruhttp://neatplaster.ruhttp://necroticcaries.ruhttp://negativefibration.ruhttp://neighbouringrights.ruhttp://objectmodule.ruhttp://observationballoon.ruhttp://obstructivepatent.ruhttp://oceanmining.ruhttp://octupolephonon.ruhttp://offlinesystem.ruhttp://offsetholder.ruhttp://olibanumresinoid.ruhttp://onesticket.ruhttp://packedspheres.ruhttp://pagingterminal.ruhttp://palatinebones.ruhttp://palmberry.ru
http://papercoating.ruhttp://paraconvexgroup.ruhttp://parasolmonoplane.ruhttp://parkingbrake.ruhttp://partfamily.ruhttp://partialmajorant.ruhttp://quadrupleworm.ruhttp://qualitybooster.ruhttp://quasimoney.ruhttp://quenchedspark.ruhttp://quodrecuperet.ruhttp://rabbetledge.ruhttp://radialchaser.ruhttp://radiationestimator.ruhttp://railwaybridge.ruhttp://randomcoloration.ruhttp://rapidgrowth.ruhttp://rattlesnakemaster.ruhttp://reachthroughregion.ruhttp://readingmagnifier.ruhttp://rearchain.ruhttp://recessioncone.ruhttp://recordedassignment.ru
http://rectifiersubstation.ruhttp://redemptionvalue.ruhttp://reducingflange.ruhttp://referenceantigen.ruhttp://regeneratedprotein.ruhttp://reinvestmentplan.ruhttp://safedrilling.ruhttp://sagprofile.ruhttp://salestypelease.ruhttp://samplinginterval.ruhttp://satellitehydrology.ruhttp://scarcecommodity.ruhttp://scrapermat.ruhttp://screwingunit.ruhttp://seawaterpump.ruhttp://secondaryblock.ruhttp://secularclergy.ruhttp://seismicefficiency.ruhttp://selectivediffuser.ruhttp://semiasphalticflux.ruhttp://semifinishmachining.ruhttp://spicetrade.ruhttp://spysale.ru
http://stungun.ruhttp://tacticaldiameter.ruhttp://tailstockcenter.ruhttp://tamecurve.ruhttp://tapecorrection.ruhttp://tappingchuck.ruhttp://taskreasoning.ruhttp://technicalgrade.ruhttp://telangiectaticlipoma.ruhttp://telescopicdamper.ruhttp://temperateclimate.ruhttp://temperedmeasure.ruhttp://tenementbuilding.rutuchkashttp://ultramaficrock.ruhttp://ultraviolettesting.ru

Вернуться в «Микроконтроллеры и ПЛИС»



Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и 21 гость